Qt: staticMetaObject is not a member of...
Just got this error message while compiling a tiny class that derives from QTreeWidgetItem
:
error C2039: 'staticMetaObject' : is not a member of 'QTreeWidgetItem'
What this is saying is that QTreeWidgetItem
does not inherit from QObject
, meaning that your own, singly-inherited class also does not inherit from QObject
. Inheriting from QObject
is one of the prerequisites to using the Q_OBJECT
macro, which, if you're anything like me, you automatically insert into any Qt GUI related class.
If you're not using any of the meta object stuff in your subclass, such as signals/slots or properties, just take out the Q_OBJECT
macro. If you need to use signals and slots, you'll need to make your subclass multiply-inherit from QObject
as well. If you take this route, remember that "Multiple Inheritance Requires QObject to Be First", otherwise you'll get either the same error as above, or something along the lines of "YourClass
inherits from two QObject subclasses" from the moc.