I have read that it measures the effectiveness of QA but I do not get it
It is surely a good idea to take any such statement about metrics with a grain of salt.
The only way I can think of to use the given metrics to measure the effectiveness of QA, is to take the same piece of code, give it to different QA people and let them independently test it. In theory, the more bugs they find, the better the QA (however, in reality the severity of the bugs found should also be incorporated).
Of course, by doing so the size of the code is fixed, so using the density as a number is quite pointless, you could actually just use "Number of bugs found by QA" as a metrics.
As you correctly have noted by yourself, as soon as you vary the QA persons and the subject under test, the metric does not tell you anything reliable about the effectiveness of the QA any more.
Since you did not give any reference where you found this questionable statement, I did a quick web search to see what others wrote about this metrics. It brought me to this page, mentioning two uses for the defect density metrics:
For comparing the relative number of defects in various software components so that high-risk components can be identified and resources focused towards them.
For comparing software/products so that quality of each software/product can be quantified and resources focused towards those with low quality.
"Effectiveness of QA" is nowhere mentioned. So according to this source, defect density is a metrics for quantifying quality aspects of the software, not of the development or QA process.
(And if you read something different in a text book, you better ask the authors of the book what they had in mind with their statements.)