When:
- I change the structure of the class (add / remove methods or change their signature);
- This class inherits from
QObject
; - Inside it uses
Q_OBJECT
,
on further compilation, I get an error:
undefined reference to `vtable for ClassName ‘
What is the reason and how to fix it?
Answer 1, authority 100%
Set the checkbox build settings to run qmake on every build
Answer 2
The fact is that the project files, namely:
- all header files,
* .cpp
– files with the line below#include & lt; cppfilename.moc & gt;
are passed through the so-called meta-object generator, which generates additional declarations and definitions for each class with Q_OBJECT
and places them in a separate * .cpp
file. For a number of reasons, the class’s virtual function table also ends up in that file.
However, these support files are not always updated on build after making changes to the source file. Therefore, after each class change, you need to clear the build directory or delete it.