[Solved] QT Error: error: undefined reference to ‘vtable for XXX’  

1. Description of problems encountered

An error occurred in a constructor during compilation:

1 error: undefined reference to ‘vtable for XXX’

2. Cause analysis

Cause of error: This usually occurs in a class that inherits QObject. It is usually a newly defined subclass that does not implement the pure virtual function of the parent class.

In QT, when you encounter this situation, you should first think of adding a new class inherited from QObject to a class and adding Q_ The macro object,

After that, this error will be reported whether it is built or rebuilt. The root cause is that only build and rebuild will be performed without compiling   Q_ Object macro (and no new MOC file will be generated),

Therefore, you need to execute qmake first and let the MOC compiler precompile Q_ Object macro. PS: you can execute qmake once before running the program

3. Solutions

Re-execute qmake and rebuild.

Generally, this problem is solved to avoid forgetting to take notes~

Similar Posts: