Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    [solved] undefined reference to 'vtable for ...'

    General and Desktop
    6
    14
    10211
    Loading More Posts
    • 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.
    • L
      lowee last edited by

      Hi everybody, I got a big problem ... I want to connect a PushButton with a slot to save some parameters but I have an error when I make the project...

      So my H file is :
      @#ifndef CONFIGRS232_H
      #define CONFIGRS232_H

      #include <QtGui>
      #include <QWidget>

      class ConfigRS232: public QWidget
      {
      Q_OBJECT

      QPushButton *saveConfigButton;
      

      public:
      ConfigRS232(QWidget *parent = 0);

      private:
      int _portCom;
      int _baudRate;
      int _dataLength;
      int _parity;
      int _stopBit;

      QComboBox *portCom;
      QComboBox *baudRate;
      QComboBox *dataLength;
      QComboBox *parity;
      QComboBox *stopBit;
      

      public slots:
      void SaveConfigParameters();
      };

      #endif // CONFIGRS232_H@

      And my .cpp file is
      @#include "configrs232.h"

      #include <iostream>
      using namespace std;

      ConfigRS232::ConfigRS232(QWidget *parent)
      : QWidget(parent)
      {
      QGroupBox *rs232ConfigGroup = new QGroupBox(tr("RS232 Configuration"));

      QLabel *pComLabel = new QLabel(tr("Com Port #"));
      portCom = new QComboBox;
      QLabel *pBaudLabel = new QLabel(tr("Bite Rate (bps):"));
      baudRate = new QComboBox;
      QLabel *pDataLabel = new QLabel(tr("Data Length:"));
      dataLength = new QComboBox;
      QLabel *pParLabel = new QLabel(tr("Parity:"));
      parity = new QComboBox;
      QLabel *pStopLabel = new QLabel(tr("Stop Bit:"));
      stopBit = new QComboBox;
      
      portCom->addItem("1",1);
      portCom->addItem("2",2);
      portCom->addItem("3",3);
      portCom->addItem("4",4);
      portCom->addItem("5",5);
      portCom->addItem("6",6);
      portCom->addItem("7",7);
      portCom->addItem("8",8);
      
      baudRate->addItem("4800",4800);
      baudRate->addItem("9600",9600);
      baudRate->addItem("19200",19200);
      baudRate->addItem("38400",38400);
      baudRate->addItem("57600",57600);
      
      dataLength->addItem("5",5);
      dataLength->addItem("6",6);
      dataLength->addItem("7",7);
      dataLength->addItem("8",8);
      
      parity->addItem("None","None");
      parity->addItem("Even","Even");
      parity->addItem("Odd","Odd");
      
      stopBit->addItem("1",1);
      stopBit->addItem("2",2);
      
      saveConfigButton = new QPushButton(tr("Save Configuration"));
      
      QGridLayout *updateLayout = new QGridLayout;
      updateLayout->addWidget(pComLabel,0,0);
      updateLayout->addWidget(portCom,0,1);
      updateLayout->addWidget(pBaudLabel,1,0);
      updateLayout->addWidget(baudRate,1,1);
      updateLayout->addWidget(pDataLabel,2,0);
      updateLayout->addWidget(dataLength,2,1);
      updateLayout->addWidget(pParLabel,3,0);
      updateLayout->addWidget(parity,3,1);
      updateLayout->addWidget(pStopLabel,4,0);
      updateLayout->addWidget(stopBit,4,1);
      rs232ConfigGroup->setLayout(updateLayout);
      
      QVBoxLayout *mainLayout = new QVBoxLayout;
      mainLayout->addWidget(rs232ConfigGroup);
      mainLayout->addWidget(rs232ConfigGroup);
      mainLayout->addSpacing(12);
      mainLayout->addWidget(saveConfigButton);
      mainLayout->addStretch(1);
      setLayout(mainLayout);
      
      connect(saveConfigButton, SIGNAL(clicked()), this, SLOT(SaveConfigParameters())); // here is my problem
      

      }

      void ConfigRS232::SaveConfigParameters()
      {
      _portCom = portCom->currentIndex();
      _baudRate = baudRate->currentIndex();
      _dataLength = dataLength->currentIndex();
      _parity = parity->currentIndex();
      _stopBit = stopBit->currentIndex();

      cout << endl << "Port Com # : " << _portCom << endl;
      

      }@

      Just for more precisions, I tried without instanciate Q_OBJECT in the .h file but it doesn't connect my pushbutton with my slot (SaveConfigParameters) ...

      Somebody have an idea ?

      We are animals that our brain gives us the feeling that we aren't

      1 Reply Last reply Reply Quote 0
      • F
        fluca1978 last edited by

        Sounds like an include problem, even if it is not clear without the exact error. Does it work if you include each single widget you use in the header file?

        1 Reply Last reply Reply Quote 0
        • L
          lowee last edited by

          I think the problem is about the instanciation of the parent class... So I tried your suggestion but the error still the same :

          @./debug\configrs232.o: In function ConfigRS232': C:\Documents and Settings\louis_fournier\Mes documents\ProjetQt\API_A429_Project\API_A429-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../API_A429/configrs232.cpp:7: undefined reference to vtable for ConfigRS232'
          C:\Documents and Settings\louis_fournier\Mes documents\ProjetQt\API_A429_Project\API_A429-build-desktop-Qt_4_7_4_for_Desktop_-MinGW_4_4__Qt_SDK__Debug/../API_A429/configrs232.cpp:7: undefined reference to vtable for ConfigRS232' C:\Documents and Settings\louis_fournier\Mes documents\ProjetQt\API_A429_Project\API_A429-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../API_A429/configrs232.cpp:7: undefined reference to vtable for ConfigRS232'
          C:\Documents and Settings\louis_fournier\Mes documents\ProjetQt\API_A429_Project\API_A429-build-desktop-Qt_4_7_4_for_Desktop
          -_MinGW_4_4__Qt_SDK__Debug/../API_A429/configrs232.cpp:7: undefined reference to vtable for ConfigRS232' ./debug\configrs232.o:C:\Documents and Settings\louis_fournier\Mes documents\ProjetQt\API_A429_Project\API_A429-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Debug/../API_A429//configrs232.h:9: undefined reference to ConfigRS232::staticMetaObject'
          collect2: ld returned 1 exit status
          mingw32-make[1]: *** [debug\API_A429.exe] Error 1
          mingw32-make: *** [debug] Error 2
          Le processus "D:\QtSDK\mingw\bin\mingw32-make.exe" s'est terminé avec le code 2.
          Erreur à la compilation du projet API_A429 (cible : Desktop)
          Lors de l'exécution de l'étape "Make"@

          So here it's my HEADER file :
          @#ifndef CONFIGRS232_H
          #define CONFIGRS232_H

          #include <QtGui>
          #include <QWidget>

          class ConfigRS232: public QWidget
          {
          Q_OBJECT

          QComboBox *portCom;
          QComboBox *baudRate;
          QComboBox *dataLength;
          QComboBox *parity;
          QComboBox *stopBit;
          
          QLabel *pComLabel;
          QLabel *pBaudLabel;
          QLabel *pDataLabel;
          QLabel *pParLabel;
          QLabel *pStopLabel;
          
          QGroupBox *rs232ConfigGroup;
          
          QGridLayout *updateLayout;
          QVBoxLayout *mainLayout;
          
          QPushButton *saveConfigButton;
          

          public:
          ConfigRS232(QWidget *parent = 0);

          private:
          int _portCom;
          int _baudRate;
          int _dataLength;
          int _parity;
          int _stopBit;

          public slots:
          void SaveConfigParameters();
          };

          #endif // CONFIGRS232_H@

          And the CPP file:
          @#include "configrs232.h"

          #include <iostream>
          using namespace std;

          ConfigRS232::ConfigRS232(QWidget *parent)
          : QWidget(parent)
          {
          rs232ConfigGroup = new QGroupBox(tr("RS232 Configuration"));

          pComLabel = new QLabel(tr("Com Port #"));
          portCom = new QComboBox;
          pBaudLabel = new QLabel(tr("Bite Rate (bps):"));
          baudRate = new QComboBox;
          pDataLabel = new QLabel(tr("Data Length:"));
          dataLength = new QComboBox;
          pParLabel = new QLabel(tr("Parity:"));
          parity = new QComboBox;
          pStopLabel = new QLabel(tr("Stop Bit:"));
          stopBit = new QComboBox;
          
          portCom->addItem("1",1);
          portCom->addItem("2",2);
          portCom->addItem("3",3);
          portCom->addItem("4",4);
          portCom->addItem("5",5);
          portCom->addItem("6",6);
          portCom->addItem("7",7);
          portCom->addItem("8",8);
          
          baudRate->addItem("4800",4800);
          baudRate->addItem("9600",9600);
          baudRate->addItem("19200",19200);
          baudRate->addItem("38400",38400);
          baudRate->addItem("57600",57600);
          
          dataLength->addItem("5",5);
          dataLength->addItem("6",6);
          dataLength->addItem("7",7);
          dataLength->addItem("8",8);
          
          parity->addItem("None","None");
          parity->addItem("Even","Even");
          parity->addItem("Odd","Odd");
          
          stopBit->addItem("1",1);
          stopBit->addItem("2",2);
          
          saveConfigButton = new QPushButton(tr("Save Configuration"));
          
          updateLayout = new QGridLayout;
          updateLayout->addWidget(pComLabel,0,0);
          updateLayout->addWidget(portCom,0,1);
          updateLayout->addWidget(pBaudLabel,1,0);
          updateLayout->addWidget(baudRate,1,1);
          updateLayout->addWidget(pDataLabel,2,0);
          updateLayout->addWidget(dataLength,2,1);
          updateLayout->addWidget(pParLabel,3,0);
          updateLayout->addWidget(parity,3,1);
          updateLayout->addWidget(pStopLabel,4,0);
          updateLayout->addWidget(stopBit,4,1);
          rs232ConfigGroup->setLayout(updateLayout);
          
          mainLayout = new QVBoxLayout;
          mainLayout->addWidget(rs232ConfigGroup);
          mainLayout->addWidget(rs232ConfigGroup);
          mainLayout->addSpacing(12);
          mainLayout->addWidget(saveConfigButton);
          mainLayout->addStretch(1);
          setLayout(mainLayout);
          
          connect(saveConfigButton, SIGNAL(clicked()), this, SLOT(SaveConfigParameters()));
          

          }

          void ConfigRS232::SaveConfigParameters()
          {
          _portCom = portCom->currentIndex();
          _baudRate = baudRate->currentIndex();
          _dataLength = dataLength->currentIndex();
          _parity = parity->currentIndex();
          _stopBit = stopBit->currentIndex();

          cout << endl << "Port Com # : " << _portCom << endl;
          

          }@

          We are animals that our brain gives us the feeling that we aren't

          1 Reply Last reply Reply Quote 0
          • R
            Rahul Das last edited by

            The above code is running perfectly for me. Couldn't reproduce the issue.

            bq. I tried without instanciate Q_OBJECT in the .h file

            You need Q_OBJECT macro, so that MOC (meta Object Compiler) will do the necessary to implement signals and slots . Refer "Meta-Object system":http://doc.qt.nokia.com/4.7/metaobjects.html#meta-object-system

            Late relpy : i meant the first post.


              Rahul Das
            

            1 Reply Last reply Reply Quote 0
            • K
              Kxyu last edited by

              Try rebuilding your project (just remove the build directory). It is a moc issue

              1 Reply Last reply Reply Quote 0
              • L
                lgeyer last edited by

                Such problems are usually solved by (manually) re-running qmake.

                1 Reply Last reply Reply Quote 0
                • L
                  lowee last edited by

                  Oh great, you're right, I deleted the build folder and that's work pretty good !! I don't really know why it doesn't work at the first time, the MOC is the pre-compiled processor instructions ?

                  We are animals that our brain gives us the feeling that we aren't

                  1 Reply Last reply Reply Quote 0
                  • L
                    lgeyer last edited by

                    No, moc is the "Meta-Object Compiler":http://doc.qt.nokia.com/latest/moc.html.

                    1 Reply Last reply Reply Quote 0
                    • L
                      lowee last edited by

                      Ok thanks, I just have two more questions ...

                      1. Do you know how can I get some values of a QComboBox (I tried with currentIndex() function and currentText but it doesn't really works...)

                      2. Which project can let me generate an application but without Qt development tool (like .exe and can be ran without problems...)

                      Anyway, I appreciate your help

                      PS: I'm a beginner with Qt ...

                      We are animals that our brain gives us the feeling that we aren't

                      1 Reply Last reply Reply Quote 0
                      • L
                        lgeyer last edited by

                        • currentIndex() and currentText() is the way to go. If they return invalid data there is most probably no item selected or the combo box is empty.
                        • Every single Application type (Qt Quick Application, Qt Gui Application, Mobile Qt Application, ...) generates a standalone binary (.exe). But you will have to distribute - as with every other non-Qt application - the "runtime dependencies":http://doc.qt.nokia.com/latest/deployment-windows.html along with your application.
                        1 Reply Last reply Reply Quote 0
                        • R
                          Rahul Das last edited by

                          In addition you can try compiling statically. so that every libraries and dependencies packed into a single executable.

                          "Ref":http://doc.qt.nokia.com/stable/deployment.html


                            Rahul Das
                          

                          1 Reply Last reply Reply Quote 0
                          • L
                            lowee last edited by

                            Thanks a lot guys! You're getting me out of every problems and I appreciate it !!

                            We are animals that our brain gives us the feeling that we aren't

                            1 Reply Last reply Reply Quote 0
                            • R
                              Rahul Das last edited by

                              You're welcome :) Happy coding :)


                                Rahul Das
                              

                              1 Reply Last reply Reply Quote 0
                              • A
                                andr1312e last edited by

                                It may happen if you change file path and header and cpp files has different paths

                                1 Reply Last reply Reply Quote 0
                                • First post
                                  Last post