4. The sum of all roots of the equation $[3 x+1]=2 x-\frac{1}{2}$ is $(\quad)$
A. -1
B. -2
C. $-\frac{5}{4}$
D. 0
4. B Let $[3 x+1]=t$, then $t$ is an integer and $0 \leqslant(3 x+1)-t<1$. Thus, the original equation becomes $t=2 x-\frac{1}{2}$, which simplifies to $x=\frac{1}{2} t+\frac{1}{4}$. Substituting the above expression into (1) yields $0 \leqslant \frac{3}{2} t+\frac{3}{4}+1-t<1$. This simplifies to $-\frac{7}{2} \leqslant t \leqslant-\frac{3}{2}$.
From (2) and $t \in \mathbf{Z}$, we know $t=-2$ or $t=-3$.
When $t=-2$, $x_{1}=-\frac{3}{4}$; when $t=-3$, $x_{2}=-\frac{5}{4}$.
Therefore, $x_{1}+x_{2}=\left(-\frac{3}{4}\right)+\left(-\frac{5}{4}\right)=-2$.