When solving a linear system, why SVD is preferred over QR to make the solution more stable?

You should check out chapter 3 in Demmel's text. Let me summarize some of the results for dense least-squares, for $A$ an $m\times n$ matrix:

  1. $A$ is well-conditioned: In this case, using the normal equations is around as accurate as other methods and is also the fastest, so using them is fine, even though they are not numerically stable.

  2. $A$ is not well-conditioned, but is not rank-deficient: Here, we we should use QR. QR is faster than the SVD and similarly stable (assuming you use a good algorithm for it i.e. not classical GS; try Householder reflections or Givens rotations).

  3. $A$ is rank-deficient: Here, QR without pivoting is faster, but less reliable than the SVD, which is slower. So, if you value reliability over speed, then you'd choose the SVD. It is worth noting that rank-revealing QR is actually between the two of them in terms of both speed and reliability.

In general, if $m\gg n$, then the costs are similar. Otherwise, QR is a bit cheaper than the SVD.

Also, as the other response says, you can truncate the SVD. If $$A=U\Sigma V^T=\sum\limits_{j=1}^n \sigma_ju_jv_j^T,$$ then the best rank $k$ approximation to $A$ in the $\left\lVert\cdot\right\rVert_2$ norm is $$A_k=\sum\limits_{j=1}^k \sigma_ju_jv_j^T=U\Sigma_k V^T,$$ where $\Sigma_k=\text{diag}(\sigma_1,\cdots,\sigma_k,0,\cdots,0).$