当前位置: 代码迷 >> QT开发 >> Qt异常 error: collect2: ld returned 1 exit status求解答,以贴源代码
  详细解决方案

Qt异常 error: collect2: ld returned 1 exit status求解答,以贴源代码

热度:322   发布时间:2016-04-25 04:42:40.0
Qt错误 error: collect2: ld returned 1 exit status求解答,以贴源代码
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
否则不会被正确编译。
  相关解决方案