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. After adding Q_OBJECT , getting compile error
QtWS25 Last Chance

After adding Q_OBJECT , getting compile error

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 3 Posters 833 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.
  • A Offline
    A Offline
    Aminul
    wrote on last edited by
    #1

    Hello, here is my header file of a very simple class.

    #ifndef MYTHREAD_H
    #define MYTHREAD_H

    #include <QObject>
    #include <QThread>

    class MyThread : public QThread
    {

    Q_OBJECT
    

    public:
    MyThread();
    void run();

    signals:
    void sending();
    };

    #endif // MYTHREAD_H

    I have corresponding CPP file. When I compile this project I am getting below error.

    g++ -m64 -o TestThread4 main.o mainwindow.o mythread.o moc_mainwindow.o -L/usr/lib/x86_64-linux-gnu -lQtGui -lQtCore -lpthread
    mythread.o: In function MyThread::MyThread()': /home/aminul/build-TestThread4-Qt_4_8_7_in_PATH_qt5-**Debug/../TestThread4/mythread.cpp:4: undefined reference to vtable for MyThread'
    Makefile:107: recipe for target 'TestThread4' failed**

    This file comiles fine, if I remove "Q_OBJECT" the project complies fine.

    What is the reason of this?

    aha_1980A 1 Reply Last reply
    0
    • A Aminul

      Hello, here is my header file of a very simple class.

      #ifndef MYTHREAD_H
      #define MYTHREAD_H

      #include <QObject>
      #include <QThread>

      class MyThread : public QThread
      {

      Q_OBJECT
      

      public:
      MyThread();
      void run();

      signals:
      void sending();
      };

      #endif // MYTHREAD_H

      I have corresponding CPP file. When I compile this project I am getting below error.

      g++ -m64 -o TestThread4 main.o mainwindow.o mythread.o moc_mainwindow.o -L/usr/lib/x86_64-linux-gnu -lQtGui -lQtCore -lpthread
      mythread.o: In function MyThread::MyThread()': /home/aminul/build-TestThread4-Qt_4_8_7_in_PATH_qt5-**Debug/../TestThread4/mythread.cpp:4: undefined reference to vtable for MyThread'
      Makefile:107: recipe for target 'TestThread4' failed**

      This file comiles fine, if I remove "Q_OBJECT" the project complies fine.

      What is the reason of this?

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by aha_1980
      #2

      @Aminul it's a linker error.

      You need to re-run qmake, then build again.

      If that doesn't help, last resort is to delete the build folder and then build again.

      Qt has to stay free or it will die.

      1 Reply Last reply
      3
      • G Offline
        G Offline
        GuYan
        wrote on last edited by GuYan
        #3

        You have build the project before you add the Q_OBJECT. You can try to make some changes in the *.pro file such as add a space at the bottom. Then re-build it, usually it will solve this problem.

        1 Reply Last reply
        1

        • Login

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