[solved] undefined reference to 'vtable for ...'
-
wrote on 21 Nov 2011, 16:59 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_OBJECTQPushButton *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 ?
-
wrote on 21 Nov 2011, 17:14 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?
-
wrote on 21 Nov 2011, 17:45 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 tovtable 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 tovtable 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_OBJECTQComboBox *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;
}@
-
wrote on 21 Nov 2011, 18:05 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.
-
wrote on 21 Nov 2011, 18:25 last edited by
Try rebuilding your project (just remove the build directory). It is a moc issue
-
wrote on 21 Nov 2011, 18:34 last edited by
Such problems are usually solved by (manually) re-running qmake.
-
wrote on 22 Nov 2011, 08:35 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 ?
-
wrote on 22 Nov 2011, 08:55 last edited by
No, moc is the "Meta-Object Compiler":http://doc.qt.nokia.com/latest/moc.html.
-
wrote on 22 Nov 2011, 09:46 last edited by
Ok thanks, I just have two more questions ...
-
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...)
-
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 ...
-
-
wrote on 22 Nov 2011, 09:56 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.
-
wrote on 22 Nov 2011, 10:07 last edited by
In addition you can try compiling statically. so that every libraries and dependencies packed into a single executable.
-
wrote on 22 Nov 2011, 11:34 last edited by
Thanks a lot guys! You're getting me out of every problems and I appreciate it !!
-
wrote on 22 Nov 2011, 11:35 last edited by
You're welcome :) Happy coding :)
-
wrote on 1 Mar 2022, 05:21 last edited by
It may happen if you change file path and header and cpp files has different paths