I don't know any details of how Quantum Espresso in particular does it, but the usual method in Kohn-Sham DFT is to simply integrate the spin density, $\sigma(\vec{r})$, over the cell, i.e.
$$
S = \int d\vec{r} \sigma(\vec{r}), \tag{1}
$$
where $S$ is the total spin and
$$
\sigma(\vec{r}) = \sum_{bk} \left\{f_{bk\uparrow}\left\vert\psi_{bk\uparrow}\left(\vec{r}\right)\right\vert^2 - f_{bk\downarrow}\left\vert\psi_{bk\downarrow}\left(\vec{r}\right)\right\vert^2\right\} \tag{2}
$$
for norm-conserving pseudopotentials. $f_{bk\uparrow}$ and $f_{bk\downarrow}$ are the occupation numbers of band $b$ at k-point $k$ for up- and down-spin channels, respectively, and $\psi_{bk\uparrow}$ and $\psi_{bk\downarrow}$ are the corresponding Kohn-Sham states. (For ultrasoft/PAW pseudopotentials you also need to include the augmentation terms.)
Equation $(1)$ gives the total spin of the simulated cell, in units of the spin of an electron, which is easily converted to your magnetic moment unit of choice. To obtain the total absolute magnetic moment, $S_\mathrm{abs}$, we just integrate the absolute spin density, i.e.
$$
S_\mathrm{abs} = \int d\vec{r} \left\vert\sigma(\vec{r})\right\vert. \tag{3}
$$
Density-mixing and self-consistency
Note that I have defined $\sigma$ to be the spin density which is consistent with the Kohn-Sham eigenstates. If you are using a density-mixing method, then there are actually two spin-densities defined in your system, the one defined by equation $(2)$, usually called $\sigma_\mathrm{out}$, and the one which was the result of the previous density mixing, usually called $\sigma_\mathrm{in}$, which is the spin-density used to calculate your exchange-correlation functional. The integrals of these two will differ, but at the end of your self-consistent field (SCF) process they should be sufficiently similar that the differences are negligible -- that's what "self-consistent" means!
In principle, you could follow your SCF process with a non-self-consistent density-of-states (DOS) calculation on a finer k-point grid, and use those Kohn-Sham states to determine the magnetic moment; however, if they differ significantly from the SCF results then that is a clue that your SCF k-point grid was not fine enough in the first place. I don't recommend that you do this routinely, except as a check of how well your results are converged with respect to your k-point sampling.
Practical details
I'm sure that QE does all the integrals for you, but if you ever need to perform them yourself, be aware that there are different normalisation conventions in use. One common convention is that the Fourier transforms are normalised when transforming from real-space to reciprocal-space, so real-space quantities like $\sigma(\vec{r})$ are not normalised in the usual way. In these circumstances any real-space quantities will be too large, by a factor of the total number of real-space grid points, $N_\mathrm{grid}$, and so when you perform the integral by summing over all the real-space points you will need to divide by $N_\mathrm{grid}$.
There is a simple way to check whether you are using the correct normalisation: perform the integral over the charge density (rather than the spin density). This should give you the number of valence electrons in the simulated cell, $N_\mathrm{elec}$, which you know already, and so it is easy to see whether the integral is $N_\mathrm{elec}$ or $N_\mathrm{elec}\times N_\mathrm{grid}$.