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 Firs/SecondClass'
Forum Updated to NodeBB v4.3 + New Features

undefined reference to 'vtable for Firs/SecondClass'

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 340 Views
  • 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.
  • S Offline
    S Offline
    Staslend
    wrote on last edited by
    #1

    I see the others topics about this problem but can't find something what can help me. I create the console aplication and try to compile but have this error. This is code :

    #include <QCoreApplication>
    #include <iostream>
    
    using namespace std;
    
    
    class FirstClass : public QObject{  //first class         (in this line error)
        Q_OBJECT
    private:
        int x;                        
    public:
        virtual ~FirstClass() {};      //the guy from stackoverflov say that this is can help  (in this line error)
    public slots:
        void change(){    //add 1 to x and if x = 4 write message to console 
            x++;
    
            if (x == 4) emit xEqu4();
        }
    signals:
        void xEqu4();       
    };
    
    class SecondClass : public QObject{  //second class   (in this line error)
      Q_OBJECT
    public:
        virtual ~SecondClass() {}    //(in this line error)
        void Work(){                  
            char c;
            for (int x = 0; x < 6 ; x++){           //you write 'g' and after 4 'g' will be the message 
            cout << "Write 'g' please" << endl;
            cin >> c;
            if (c == 'g') emit ch();//(in this line error)
            }
        }
    public slots:
        void goodbye(){
            cout << "Goodbye!!!" << endl;  //this is message
        }
    signals:
        void ch();
    };
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        FirstClass f;
        SecondClass s;
    
        QObject::connect(&s, SIGNAL(ch()),
                         &f, SLOT(change()));
        QObject::connect(&f, SIGNAL(xEqu4()),
                         &s, SLOT(goodbye()));
    
        s.Work();
    
        return a.exec();
    }
    
    

    And a .pro file if you need it, i didn`t toch it:

    QT -= gui
    
    CONFIG += c++11 console
    CONFIG -= app_bundle
    
    
    # The following define makes your compiler emit warnings if you use
    # any feature of Qt which as been marked deprecated (the exact warnings
    # depend on your compiler). Please consult the documentation of the
    # deprecated API in order to know how to port your code away from it.
    DEFINES += QT_DEPRECATED_WARNINGS
    
    # You can also make your code fail to compile if you use deprecated APIs.
    # In order to do so, uncomment the following line.
    # You can also select to disable deprecated APIs only up to a certain version of Qt.
    #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
    
    SOURCES += \
            main.cpp
    
    

    How to solwe this problem?

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      You can't have multiple Q_OBJECT macros in the same file, moc can't handle it. move the two classes in separate header files

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      2

      • Login

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