Example 1 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$ .
$$
\begin{array}{l}
\left(x^{4}+2 x^{3}+x^{2}\right)+\left[(2+k) x^{2}+(2+k) x\right]+2 k=0 \\
\Rightarrow\left(x^{2}+x\right)^{2}+(2+k)\left(x^{2}+x\right)+2 k=0 \\
\Rightarrow\left(x^{2}+x+2\right)\left(x^{2}+x+k\right)=0 .
\end{array}
$$

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