8.4. Q_OBJECT and moc: A checklist

[ fromfile: qobject.xml id: moc ]

[Note] Multiple Inheritance and QObject
  • Because each Q_OBJECT macro generates code, it needs to be preprocessed by moc.

  • moc works under the assumption that you are only deriving from QObject once and, further, that QObject is the first base class in the list of base classes.

  • If you accidentally inherit from QObject more than once, or if it is not the first base class in the inheritance list, you may produce strange errors in the moc-generated code.

[Note] Undefined reference to vtable

If you define a QObject-derived class, build an application, realize that you need to add the Q_OBJECT macro to the class definition, and add it after the project was built with an old Makefile, you must then rerun qmake to update the Makefile.

make is not smart enough to add the moc step on such files to your Makefile otherwise. A "clean rebuild" does not fix this problem usually. This is an issue that often causes headaches for inexperienced Qt developers. For more information about this error message, see Section C.3.1



[40] confusing + obfuscated