- C/C++ code
#include<QThread>#include<QCoreApplication>#include<iostream>using namespace std;class MyThread : public QThread { Q_OBJECT public: MyThread(); ~MyThread(); protected: void run() { cout << "I run the thread" <<endl; } };MyThread::MyThread(){}MyThread::~MyThread(){}int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); MyThread myThread; myThread.start(); return a.exec(); }
: error: collect2: ld returned 1 exit status
: undefined reference to `vtable for MyThread'
------解决方案--------------------
用到了:Q_OBJECT宏,就要老老实实的按照要求来写代码。
这个程序要分成3个文件。
MyThread.h
MyThread.cpp
main.cpp
否则不会被正确编译。