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. undefined reference to `vtable for myclass'
Qt 6.11 is out! See what's new in the release blog

undefined reference to `vtable for myclass'

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 4.9k 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.
  • F Offline
    F Offline
    fireghostea
    wrote on last edited by
    #1

    this is my header file for my class

    #ifndef MASTERPAGEHANDLER_H
    #define MASTERPAGEHANDLER_H
    #include <QThread>
    #include <QObject>
    
    
    
    
    class MasterPageHandler : public QObject
    {
        Q_OBJECT
    
    
    public :
        Q_INVOKABLE bool status() const;
    public:
    
        bool m_status;
    public:
        //explicit MasterPageHandler(QObject *parent = nullptr);
         MasterPageHandler();
    signals:
    void wirelessStateChange_signal();
    public slots:
    void timer_tick_slot();
    void scanProcessFinished(QString res);
    };
    
    
    
    #endif // MASTERPAGEHANDLER_H
    
    

    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 {
    Q_OBJECT
    public :
        myScanner(){}
        void run(){
                NetworkManagment *nm=new NetworkManagment();
                QString s=nm->CheckWifiOnline();
                emit finishProcess(s);
        }
    signals :
       void finishProcess(QString res);
    };
    
    MasterPageHandler::MasterPageHandler()
        : 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);
        ms->start();
    }
    
    

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

    kshegunovK A 2 Replies Last reply
    0
    • F fireghostea

      this is my header file for my class

      #ifndef MASTERPAGEHANDLER_H
      #define MASTERPAGEHANDLER_H
      #include <QThread>
      #include <QObject>
      
      
      
      
      class MasterPageHandler : public QObject
      {
          Q_OBJECT
      
      
      public :
          Q_INVOKABLE bool status() const;
      public:
      
          bool m_status;
      public:
          //explicit MasterPageHandler(QObject *parent = nullptr);
           MasterPageHandler();
      signals:
      void wirelessStateChange_signal();
      public slots:
      void timer_tick_slot();
      void scanProcessFinished(QString res);
      };
      
      
      
      #endif // MASTERPAGEHANDLER_H
      
      

      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 {
      Q_OBJECT
      public :
          myScanner(){}
          void run(){
                  NetworkManagment *nm=new NetworkManagment();
                  QString s=nm->CheckWifiOnline();
                  emit finishProcess(s);
          }
      signals :
         void finishProcess(QString res);
      };
      
      MasterPageHandler::MasterPageHandler()
          : 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);
          ms->start();
      }
      
      

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

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      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.

      Read and abide by the Qt Code of Conduct

      F 1 Reply Last reply
      3
      • F fireghostea

        this is my header file for my class

        #ifndef MASTERPAGEHANDLER_H
        #define MASTERPAGEHANDLER_H
        #include <QThread>
        #include <QObject>
        
        
        
        
        class MasterPageHandler : public QObject
        {
            Q_OBJECT
        
        
        public :
            Q_INVOKABLE bool status() const;
        public:
        
            bool m_status;
        public:
            //explicit MasterPageHandler(QObject *parent = nullptr);
             MasterPageHandler();
        signals:
        void wirelessStateChange_signal();
        public slots:
        void timer_tick_slot();
        void scanProcessFinished(QString res);
        };
        
        
        
        #endif // MASTERPAGEHANDLER_H
        
        

        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 {
        Q_OBJECT
        public :
            myScanner(){}
            void run(){
                    NetworkManagment *nm=new NetworkManagment();
                    QString s=nm->CheckWifiOnline();
                    emit finishProcess(s);
            }
        signals :
           void finishProcess(QString res);
        };
        
        MasterPageHandler::MasterPageHandler()
            : 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);
            ms->start();
        }
        
        

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

        A Offline
        A Offline
        alex_malyu
        wrote on last edited by
        #3

        @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.

        1 Reply Last reply
        0
        • kshegunovK kshegunov

          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.

          F Offline
          F Offline
          fireghostea
          wrote on last edited by
          #4

          @kshegunov tnx solved

          kshegunovK 1 Reply Last reply
          0
          • F fireghostea

            @kshegunov tnx solved

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by kshegunov
            #5

            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.

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

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            4
            • J Offline
              J Offline
              jAMES444
              Banned
              wrote on last edited by
              #6
              This post is deleted!
              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