A New Krazy Checker for Classes Requiring Q_OBJECT

Thorsten Röder thorsten.roeder at weihenstephan.org
Fri May 11 14:41:28 BST 2007

Am 11.05.2007 um 11:46 schrieb Thiago Macieira:

> Tom Albers said:
>> At Friday 11 May 2007 01:05, you wrote:
>>> Tonight's Krazy run will start looking for QObject derived classes
>>> that are without the Q_OBJECT macro.  This new checker was written
>>> by  Thorsten Roeder.
>> I thought that was only needed when there are signals or slots?
>> Toma
> The test only checks direct derivation from QObject. If you don't  
> need any
> of the Meta Object features (properties, signals, slots, enums,  
> className,
> qobject_cast, the meta object itself, etc.) why are you deriving from
> QObject in the first place? :-)
> QObjects are heavy: if you don't need any of those features, you  
> shouldn't
> derive from it.
> Arguably, there might be a reason to derive in the QObject hierarchy
> without including a Q_OBJECT macro, for instance to access a protected
> member function, etc. But I don't believe it exists for direct QObject
> derivation.

[1] recommends the use the Q_OBJECT macro for all subclasses of  
QObject too:

"While it is possible to use QObject as a base class without the  
Q_OBJECT macro
and without meta-object code, neither signals and slots nor the other  
described here will be available if the Q_OBJECT macro is not used.  
 From the
meta-object system's point of view, a QObject subclass without meta  
code is
equivalent to its closest ancestor with meta-object code. This means  
for example,
that QMetaObject::className() will not return the actual name of your  
class, but
the class name of this ancestor.
Therefore, we strongly recommend that all subclasses of QObject use the
Q_OBJECT macro regardless of whether or not they actually use  
signals, slots,
and properties."

[1] http://doc.trolltech.com/4.3/metaobjects.html


More information about the kde-core-devel mailing list