Qt meta-objects
Most of the special functionality that Qt offers revolves around the QObject
class and the meta-object paradigm that we will take a closer look at now. The paradigm says that with every QObject
subclass, there is a special object associated that contains information about that class. It allows us to make runtime queries to learn useful things about the class—the class name, superclass, constructors, methods, fields, enumerations, and so on. The meta-object is generated for the class at compile time when three conditions are met:
The class is a descendant of
QObject
It contains a special
Q_OBJECT
macro in a private section of its definitionCode of the class is preprocessed by a special Meta-Object Compiler (moc) tool
We can comply to the first two conditions ourselves by writing proper code for the class just like Qt Creator does when we create a class derived from QObject
. The last condition is met automatically when you use a tool chain that comes with Qt (and Qt Creator)...