Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved]He said "undefined reference to 'vtable for MyTask(class)' "

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • joeQJ Offline
    joeQJ Offline
    joeQ
    wrote on last edited by joeQ
    #1

    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)'"
    }
    

    Just do it!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      joeQJ 1 Reply Last reply
      1
      • SGaistS SGaist

        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.

        joeQJ Offline
        joeQJ Offline
        joeQ
        wrote on last edited by
        #3

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

        Just do it!

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved