Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
After adding Q_OBJECT , getting compile error
Aminul last edited by
Hello, here is my header file of a very simple class.
class MyThread : public QThread
#endif // MYTHREAD_H
I have corresponding CPP file. When I compile this project I am getting below error.
g++ -m64 -o TestThread4 main.o mainwindow.o mythread.o moc_mainwindow.o -L/usr/lib/x86_64-linux-gnu -lQtGui -lQtCore -lpthread
mythread.o: In function
MyThread::MyThread()': /home/aminul/build-TestThread4-Qt_4_8_7_in_PATH_qt5-**Debug/../TestThread4/mythread.cpp:4: undefined reference tovtable for MyThread'
Makefile:107: recipe for target 'TestThread4' failed**
This file comiles fine, if I remove "Q_OBJECT" the project complies fine.
What is the reason of this?
@Aminul it's a linker error.
You need to re-run
qmake, then build again.
If that doesn't help, last resort is to delete the build folder and then build again.
GuYan last edited by GuYan
You have build the project before you add the Q_OBJECT. You can try to make some changes in the *.pro file such as add a space at the bottom. Then re-build it, usually it will solve this problem.