In Qt, an error about undefined reference to 'vtable for'

In Qt, the information communication between different dialog boxes or controls in different windows is realized through the signal and slot mechanism.
This requires declaring this macro in the class header file:Q_OBJECT

Q_OBJECTThe fundamental reason why signals and slots can communicate is that QtCreator will automatically create a moc_...cpp file after adding it in the header file of the class , which is used to implement the code for communication between signals and slots. However, sometimes when we create a class through QtCreator, we do not select it to be derived from the QObject class through the IDE option, but add it later, and QtCreator does not automatically create the moc_...cpp file.
At this time, such an error message will appear in the source file of the class: undefined reference to 'vtable for ...'

Solution:
1. Remove the header file of the source file from the header file.
2. Add the header file of the source file from the existing file, so that QtCreator will automatically create the moc_...cpp file for this class.

Guess you like

Origin blog.csdn.net/weixin_46060711/article/details/128522527