4. As shown in Figure 2, the radius of hemisphere $O$ is $R$, and the rectangular prism $A B C D$ $A_{1} B_{1} C_{1} D_{1}$ is inscribed in the hemisphere $O$ with one of its faces $A B C D$ on the base of the hemisphere $O$. Then the maximum value of the sum of all the edges of the rectangular prism is
4.12R.

Let $A B=a, A D=b, A A_{1}=c$, and connect $O A_{1}$.
In the right triangle $\triangle A_{1} A O$, we have $\frac{a^{2}+b^{2}}{4}+c^{2}=R^{2}$.
Thus, $\frac{5}{4} a^{2}+\frac{5}{4} b^{2}+8 c^{2}$
$=\left(a^{2}+b^{2}\right)+\left(\frac{b^{2}}{4}+4 c^{2}\right)+\left(4 c^{2}+\frac{a^{2}}{4}\right)$
$\geqslant 2 a b+2 b c+2 c a$.
Adding $a^{2}+b^{2}+c^{2}$ to both sides of the above inequality, we get
$$
9\left(\frac{a^{2}+b^{2}}{4}+c^{2}\right) \geqslant(a+b+c)^{2},
$$

which means $9 R^{2} \geqslant(a+b+c)^{2}$.
Therefore, $a+b+c \leqslant 3 R$.
The equality holds if and only if $a=b=4 c=\frac{4 R}{3}$.
Hence, the maximum value of the sum of all edges of the rectangular prism is $12 R$.