I recently posted a question about the overhead of QObject in typical usage scenarios, but unfortunately the question got closed as a duplicate of another question that didn't technically answer the question.
What is worse, the hasty "Samaritans" who politely rushed to close my question interrupted the answer I was just finishing typing after running a few tests. Since I can no longer post my findings in my original question, I'll post it here so it is available to others who might need that information.
There are several reasons why a QObject can't be copied. The two biggest reasons are: QObjects usually communicate with each other using the signals and slots mechanism. It's unclear whether the connected signals and/or slots should be transferred over to the copy.
QObject is the heart of the Qt Object Model. The central feature in this model is a very powerful mechanism for seamless object communication called signals and slots. You can connect a signal to a slot with connect() and destroy the connection with disconnect().
The Q_OBJECT macro is used to enable meta-object features when declared within a class definition. The Meta-Object Compiler ( moc ) will read the class definitions with the declared Q_OBJECT macro and produce the meta-object code.
A lot of people have hinted at QObject being heavy, but without any clarity on how heavy is it exactly. So I did some measurements, not very accurate, all values are approximate.
Those numbers should take into account I am using a 64 bit Qt build.
So, in conclusion, the overhead of QObject is quite significant indeed. Nothing to sneeze at or overuse.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With