undefined reference to `vtable for myclass'

  • this is my header file for my class

    #include <QThread>
    #include <QObject>
    class MasterPageHandler : public QObject
    public :
        Q_INVOKABLE bool status() const;
        bool m_status;
        //explicit MasterPageHandler(QObject *parent = nullptr);
    void wirelessStateChange_signal();
    public slots:
    void timer_tick_slot();
    void scanProcessFinished(QString res);

    and this is my cpp file and i define another class in it for thread

    #include "masterpagehandler.h"
    #include <QDebug>
    #include "Utility/networkmanagment.h"
    class myScanner :public QThread {
    public :
        void run(){
                NetworkManagment *nm=new NetworkManagment();
                QString s=nm->CheckWifiOnline();
                emit finishProcess(s);
    signals :
       void finishProcess(QString res);
        : m_status(false)
    bool MasterPageHandler::status() const
        return m_status;
    void MasterPageHandler::scanProcessFinished(QString res){
    void MasterPageHandler::timer_tick_slot(){
        myScanner *ms = new myScanner();
        connect(ms , &myScanner::objectNameChanged, this , &MasterPageHandler::scanProcessFinished);

    i get this error undefined reference to `vtable for myScanner'

  • Qt Champions 2017

    My suspicion is because your constructor is inlined, so g++ (which I'm pretty sure you use) doesn't know where to emit the vtable. Anyway, move the class into the header and use a non-inline constructor, rebuild and it should be fixed.

  • @fireghostea

    Your class myScanner needs to be mocked (preprocessed by Qt).
    Typically it is done by placing QObject subclass in a separate header file.
    If you want to put it in cpp, you have to manually include the moc file.
    Other actions may be required depending on your build tool.

  • @kshegunov tnx solved

  • Qt Champions 2017

    For further reference, g++ will emit the vtable just before the first non-inline function (MSVC doesn't have that problem for reasons beyond the scope of this discussion). Meaning it's a good idea to have your constructor in source to avoid this rather cryptic error.

    If the solution is satisfactory, please mark the thread as solved. We like seeing green instead of orange in the list. Thank you.

  • Banned

    This post is deleted!

Log in to reply

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