[ fromfile: qobject.xml id: moc ]
QObject supports features not normally available in C++ objects.
Signals and Slots (Section 8.5)
MetaObjects, MetaProperties, MetaMethods (Chapter 12)
qobject_cast
(Section 12.2)
Some of 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 Q_OBJECT 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[69] when moc cannot find or process a class in the project. To help ensure that moc processes each QObject-derived class in the project, following are some guidelines for writing C++ code and qmake project files.
Each class
definition should go in its own .h
file.
Its implementation should go in a corresponding .cpp
file.
The header file should be "wrapped" (e.g., with #ifndef
) to avoid multiple inclusion.
Each .cpp
file should be listed in the SOURCES
variable of the project file; otherwise it will not be compiled.
Each header file should be listed in the HEADERS
variable of the .pro
file. Without this, moc will not preprocess the file.
The Q_OBJECT
macro must appear inside the class
definition of each QObject derived header file so that moc knows to generate code for it.
Undefined reference to vtable | |
---|---|
If you define a QObject-derived class, build an application, realize that you need to add the |
Generated: 2012-03-02 | © 2012 Alan Ezust and Paul Ezust. |