4. Given the equation in $x$
$$
x^{4}+2 x^{3}+(3+k) x^{2}+(2+k) x+2 k=0
$$

has real roots. If the product of all real roots is -2, then the sum of the squares of all real roots is $\qquad$ .
4.5.

Factorizing the left side of the equation, we get
$$
\left(x^{2}+x+2\right)\left(x^{2}+x+k\right)=0 \text {. }
$$

Since $x^{2}+x+2=0$ has no real roots, the equation $x^{2}+x+k=0$ has two real roots $x_{1} 、 x_{2}$.
According to the problem, $x_{1} x_{2}=k=-2$.
$$
\begin{array}{l}
\text { Also, } x_{1}+x_{2}=-1 \text {, so } \\
x_{1}^{2}+x_{2}^{2}=\left(x_{1}+x_{2}\right)^{2}-2 x_{1} x_{2}=5 .
\end{array}
$$