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. Q_OBJECT compile error... T^T
QtWS25 Last Chance

Q_OBJECT compile error... T^T

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

    If I comment out the line that contains Q_OBJECT, it compiles fine. (but, SLOT does not work.)

    I have found a case that has experienced similar problems, but I don't know how to apply it to this source.

    please help me

    .h file

    #ifndef ROOMBUTTON_H
    #define ROOMBUTTON_H
    #include <QPushButton>
    
    class RoomButton : public QPushButton
    {
        Q_OBJECT // This line is error..
    
    public:
        RoomButton();
    
    
    public slots:
        void roomClicked();
    
    signals:
        void textChanged(QString &str);
    
    private:
        QString temp;
    
    
    };
    
    #endif // ROOMBUTTON_H
    

    .cpp file

    #include "roombutton.h"
    #include <QPushButton>
    
    RoomButton::RoomButton()
    {
        QSizePolicy sizePolicy2(QSizePolicy::Minimum, QSizePolicy::Preferred);
        this->setSizePolicy(sizePolicy2);
    
        QFont font = this->font();
        font.setPointSize(24);
        this->setFont(font);
    
        QObject::connect(this,SIGNAL(clicked()),
                this,SLOT(roomClicked()));
    }
    
    void RoomButton::roomClicked()
    {
        if (temp != this->text()) {
        temp = this->text();
        emit textChanged(temp);
        }
    }
    
    void RoomButton::textChanged(QString &str){
    }
    

    compile error code

    roombutton.cpp:4: error: undefined reference to `vtable for RoomButton'
    

    Thanks in advance for your help.

    JKSHJ J.HilkJ 2 Replies Last reply
    0
    • K Kycho

      If I comment out the line that contains Q_OBJECT, it compiles fine. (but, SLOT does not work.)

      I have found a case that has experienced similar problems, but I don't know how to apply it to this source.

      please help me

      .h file

      #ifndef ROOMBUTTON_H
      #define ROOMBUTTON_H
      #include <QPushButton>
      
      class RoomButton : public QPushButton
      {
          Q_OBJECT // This line is error..
      
      public:
          RoomButton();
      
      
      public slots:
          void roomClicked();
      
      signals:
          void textChanged(QString &str);
      
      private:
          QString temp;
      
      
      };
      
      #endif // ROOMBUTTON_H
      

      .cpp file

      #include "roombutton.h"
      #include <QPushButton>
      
      RoomButton::RoomButton()
      {
          QSizePolicy sizePolicy2(QSizePolicy::Minimum, QSizePolicy::Preferred);
          this->setSizePolicy(sizePolicy2);
      
          QFont font = this->font();
          font.setPointSize(24);
          this->setFont(font);
      
          QObject::connect(this,SIGNAL(clicked()),
                  this,SLOT(roomClicked()));
      }
      
      void RoomButton::roomClicked()
      {
          if (temp != this->text()) {
          temp = this->text();
          emit textChanged(temp);
          }
      }
      
      void RoomButton::textChanged(QString &str){
      }
      

      compile error code

      roombutton.cpp:4: error: undefined reference to `vtable for RoomButton'
      

      Thanks in advance for your help.

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      @Kycho said in Q_OBJECT compile error... T^T:

      compile error code

      roombutton.cpp:4: error: undefined reference to `vtable for RoomButton'
      

      You have some stale files in the build directory. There are a few different ways to fix it:

      • Click Build > Clean Project _____, OR
      • Manually delete your build folder, OR
      • Click Build > Run qmake (assuming you're using qmake)

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      K 1 Reply Last reply
      5
      • JKSHJ JKSH

        @Kycho said in Q_OBJECT compile error... T^T:

        compile error code

        roombutton.cpp:4: error: undefined reference to `vtable for RoomButton'
        

        You have some stale files in the build directory. There are a few different ways to fix it:

        • Click Build > Clean Project _____, OR
        • Manually delete your build folder, OR
        • Click Build > Run qmake (assuming you're using qmake)
        K Offline
        K Offline
        Kycho
        wrote on last edited by
        #3

        @JKSH
        Thank you so much for solving the problem.

        1 Reply Last reply
        0
        • K Kycho

          If I comment out the line that contains Q_OBJECT, it compiles fine. (but, SLOT does not work.)

          I have found a case that has experienced similar problems, but I don't know how to apply it to this source.

          please help me

          .h file

          #ifndef ROOMBUTTON_H
          #define ROOMBUTTON_H
          #include <QPushButton>
          
          class RoomButton : public QPushButton
          {
              Q_OBJECT // This line is error..
          
          public:
              RoomButton();
          
          
          public slots:
              void roomClicked();
          
          signals:
              void textChanged(QString &str);
          
          private:
              QString temp;
          
          
          };
          
          #endif // ROOMBUTTON_H
          

          .cpp file

          #include "roombutton.h"
          #include <QPushButton>
          
          RoomButton::RoomButton()
          {
              QSizePolicy sizePolicy2(QSizePolicy::Minimum, QSizePolicy::Preferred);
              this->setSizePolicy(sizePolicy2);
          
              QFont font = this->font();
              font.setPointSize(24);
              this->setFont(font);
          
              QObject::connect(this,SIGNAL(clicked()),
                      this,SLOT(roomClicked()));
          }
          
          void RoomButton::roomClicked()
          {
              if (temp != this->text()) {
              temp = this->text();
              emit textChanged(temp);
              }
          }
          
          void RoomButton::textChanged(QString &str){
          }
          

          compile error code

          roombutton.cpp:4: error: undefined reference to `vtable for RoomButton'
          

          Thanks in advance for your help.

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @Kycho
          There is more to fix (the constructor) or you'll end up with strange errors later down the road.

          public:
              RoomButton();
          
          //to
             explicit RoomButton(QWidget *parent = nullptr);
          
          RoomButton::RoomButton()
          {
              QSizePolicy sizePolicy2(QSizePolicy::Minimum, QSizePolicy::Preferred);
              this->setSizePolicy(sizePolicy2);
          
              QFont font = this->font();
              font.setPointSize(24);
              this->setFont(font);
          
              QObject::connect(this,SIGNAL(clicked()),
                      this,SLOT(roomClicked()));
          }
          
          // to
          RoomButton::RoomButton(QWidget *parent)  : QPushButton(parent);
          {
              QSizePolicy sizePolicy2(QSizePolicy::Minimum, QSizePolicy::Preferred);
              this->setSizePolicy(sizePolicy2);
          
              QFont font = this->font();
              font.setPointSize(24);
              this->setFont(font);
          
              QObject::connect(this,SIGNAL(clicked()),
                      this,SLOT(roomClicked()));
          }
          

          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          K 1 Reply Last reply
          4
          • J.HilkJ J.Hilk

            @Kycho
            There is more to fix (the constructor) or you'll end up with strange errors later down the road.

            public:
                RoomButton();
            
            //to
               explicit RoomButton(QWidget *parent = nullptr);
            
            RoomButton::RoomButton()
            {
                QSizePolicy sizePolicy2(QSizePolicy::Minimum, QSizePolicy::Preferred);
                this->setSizePolicy(sizePolicy2);
            
                QFont font = this->font();
                font.setPointSize(24);
                this->setFont(font);
            
                QObject::connect(this,SIGNAL(clicked()),
                        this,SLOT(roomClicked()));
            }
            
            // to
            RoomButton::RoomButton(QWidget *parent)  : QPushButton(parent);
            {
                QSizePolicy sizePolicy2(QSizePolicy::Minimum, QSizePolicy::Preferred);
                this->setSizePolicy(sizePolicy2);
            
                QFont font = this->font();
                font.setPointSize(24);
                this->setFont(font);
            
                QObject::connect(this,SIGNAL(clicked()),
                        this,SLOT(roomClicked()));
            }
            
            K Offline
            K Offline
            Kycho
            wrote on last edited by
            #5

            @J.Hilk

            I modified the source according to your advice.
            Thank you so much!!

            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