[solved]He said "undefined reference to 'vtable for MyTask(class)' "



  • Would you help me? Thank you!
    My program is little,

    mytask.h

    #ifndef MYTASK_H
    #define MYTASK_H
    #include <QRunnable>
    #include <QObject>
    #include <QDebug>
    class MyTask : public QObject,public QRunnable//inherit object and runnable
    {
        Q_OBJECT
    public:
        MyTask();
    signals:
        void Result(int iNumber);//my signals
    
    protected:
        void run();
    };
    
    #endif // MYTASK_H
    
    

    mytask.cpp

    #include "mytask.h"
    
    MyTask::MyTask()//first error at here,it said: " error: undefined reference to `vtable for MyTask'"
    {
    
    }
    
    void MyTask::run()
    {
        qDebug()<<"Tesk Run...";
        int iNumber = 0;
        for(int i=0; i<100; ++i)
        {
            iNumber += i;
        }
        qDebug()<<"Task done!";
        emit Result(iNumber);//second at here it said:" error: undefined reference to `MyTask::Result(int)'"
    }
    

  • Lifetime Qt Champion

    Hi,

    Usually it's because you added/removed the Q_OBJECT macro without re-running qmake. Re-run it and you should be good to build.



  • @SGaist Yes,it is ok! I ran qmake and ran all,it is ok! thank you very much!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.