Important: Please read the Qt Code of Conduct -

undefined reference to 'vtable for Firs/SecondClass'

  • 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)
        int x;                        
        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 
            if (x == 4) emit xEqu4();
        void xEqu4();       
    class SecondClass : public QObject{  //second class   (in this line error)
        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
        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()));
        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.
    # 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 += \

    How to solwe this problem?

  • 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

Log in to reply