Weak lensing by line-of-sight haloes as the origin of flux-ratio anomalies in quadruply lensed QSOs