Link error in test unit with QOBJECT macro
-
Hi all,
I have created a dll project. This one build without errors.
I want to test this dll so I create a QtTest class.
But when I try to build the unit test .pro I get the following errors :tst_testsconnection.obj : error LNK2001: symbole externe non résolu "public: virtual void * __cdecl QSerialPort::`scalar deleting destructor'(unsigned int)" (??_GQSerialPort@@UEAAPEAXI@Z) tst_testsconnection.obj : error LNK2001: symbole externe non résolu "public: virtual void * __cdecl QSerialPort::`vector deleting destructor'(unsigned int)" (??_EQSerialPort@@UEAAPEAXI@Z)In my Dll I have a class who uses QSerialPort. But I have no issue on how to fix this link error.
If I remove the QOBJECT macro and the signals/slot part there is no more any link errors.
My dll project was created using QtCreator wizard.Below the .h of my class in the dll :
#ifndef RS232UNIWHEEL_H #define RS232UNIWHEEL_H #include "connectionlibrary_global.h" #include <QObject> #include <QtSerialPort/QSerialPort> class CONNECTIONLIBRARYSHARED_EXPORT RS232UniWheel : public QObject { Q_OBJECT public: RS232UniWheel(); ~RS232UniWheel(); void open(); bool isOpen(); void close(); void writeList(); void writeStart(); void writeStop(); QByteArray readAll(); QString getError(); signals: void errorOccurred(QSerialPort::SerialPortError error); void readyRead(); public slots: void readData(); void handleError(QSerialPort::SerialPortError error); private : QSerialPort m_serial; }; #endif // RS232UNIWHEEL_HAll these are quite simple usage of Qt code.
If anyone has an idea ??
Thanks.
-
@CHPOG said in Link error in test unit with QOBJECT macro:
~RS232UniWheel();
Did you actually implement this ctor?
-
Hi all,
I have created a dll project. This one build without errors.
I want to test this dll so I create a QtTest class.
But when I try to build the unit test .pro I get the following errors :tst_testsconnection.obj : error LNK2001: symbole externe non résolu "public: virtual void * __cdecl QSerialPort::`scalar deleting destructor'(unsigned int)" (??_GQSerialPort@@UEAAPEAXI@Z) tst_testsconnection.obj : error LNK2001: symbole externe non résolu "public: virtual void * __cdecl QSerialPort::`vector deleting destructor'(unsigned int)" (??_EQSerialPort@@UEAAPEAXI@Z)In my Dll I have a class who uses QSerialPort. But I have no issue on how to fix this link error.
If I remove the QOBJECT macro and the signals/slot part there is no more any link errors.
My dll project was created using QtCreator wizard.Below the .h of my class in the dll :
#ifndef RS232UNIWHEEL_H #define RS232UNIWHEEL_H #include "connectionlibrary_global.h" #include <QObject> #include <QtSerialPort/QSerialPort> class CONNECTIONLIBRARYSHARED_EXPORT RS232UniWheel : public QObject { Q_OBJECT public: RS232UniWheel(); ~RS232UniWheel(); void open(); bool isOpen(); void close(); void writeList(); void writeStart(); void writeStop(); QByteArray readAll(); QString getError(); signals: void errorOccurred(QSerialPort::SerialPortError error); void readyRead(); public slots: void readData(); void handleError(QSerialPort::SerialPortError error); private : QSerialPort m_serial; }; #endif // RS232UNIWHEEL_HAll these are quite simple usage of Qt code.
If anyone has an idea ??
Thanks.
@CHPOG said in Link error in test unit with QOBJECT macro:
tst_testsconnection.obj : error LNK2001: symbole externe non résolu "public: virtual void * __cdecl QSerialPort::`scalar deleting destructor'(unsigned int)" (??_GQSerialPort@@UEAAPEAXI@Z) tst_testsconnection.obj : error LNK2001: symbole externe non résolu "public: virtual void * __cdecl QSerialPort::`vector deleting destructor'(unsigned int)" (??_EQSerialPort@@UEAAPEAXI@Z)Is
QtSerialPortincluded in your project file?
(https://stackoverflow.com/questions/20044185/qt-linker-error-when-adding-class-to-basic-qt-gui-application)Check if all functions / slots are implemented in your cpp files.
Try a cleanup and qmake / build again -
@CHPOG said in Link error in test unit with QOBJECT macro:
~RS232UniWheel();
Did you actually implement this ctor?
@Christian-Ehrlicher
Yes I try but no more successfull. And the link error is on the destructor of QSerialPort not Rs232UniWhelll one.@Pl45m4
Yes I had QT += serialport in my .pro file.
Before I forgot to add it but I had much more link error.
All functions/slots are implemented in my cpp files.
And I also try to delete the build directory and do a new build. -
Hi,
What compiler are you using ?
What version of Qt are you building your test with ? -
@SGaist
I use QtCreator 4.9.2.
I don't really know which compiler I use. I just click on the Rebuild popup menu in the project.
After take a look I used MSVC compiler and want to use Mingw. But when changing to mingw compilation failed, this is an other issue when I want to emit signals I have a undefined reference/ConnectionLibrary/RS232UniWheel.cpp:16: undefined reference to `RS232UniWheel::errorOccurred(QSerialPort::SerialPortError)'
void RS232UniWheel::handleError(QSerialPort::SerialPortError error) { emit errorOccurred(error); }