Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How heavy is QObject really? [duplicate]

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.

like image 352
dtech Avatar asked Apr 02 '13 11:04

dtech


People also ask

Is QObject copyable?

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.

What is QObject in Qt?

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().

What is Q_object macro?

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.


1 Answers

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.

  • unused QObject ~160 bytes
  • single auto connection w/o arguments ~235 bytes
  • 2 auto connections w/o arguments ~315 bytes
  • 3 auto connections, 1 with 3 arguments ~400 bytes
  • 2 auto connections, 1 queued with 3 arguments ~432 bytes

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.

like image 182
dtech Avatar answered Sep 22 '22 11:09

dtech