Q_OBJECT and moc: A Checklist

Q_OBJECT and moc A Checklist

QObject supports features not normally available in C++ objects.

These features are only possible through the use of generated code. The Meta Object Compiler, moc, generates additional functions for each QObject-derived class that uses the macro. Generated code can be found in files with names moc_filename.cpp.

This means that some errors from the compiler/linker may be confuscated[5] when moc is not able to find or process your classes. To help ensure that moc processes each of your QObject-derived classes, here are some guidelines for writing C++ code and qmake project files.

[5] confusing + obfuscated

Multiple Inheritance and QObject

Because each Q_OBJECT has signals and slots, it needs to be preprocessed by moc.moc works under the assumption that you are only deriving from QObject once, and further, that it is the first base class in the list of base classes. If you accidentally inherit from QObject multiple times, or if it is not the first base class in the inheritance list, you may receive very strange errors from moc-generated code.

Категории