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. Link error in test unit with QOBJECT macro

Link error in test unit with QOBJECT macro

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 756 Views 2 Watching
  • 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.
  • C Offline
    C Offline
    CHPOG
    wrote on last edited by CHPOG
    #1

    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_H
    
    

    All these are quite simple usage of Qt code.

    If anyone has an idea ??

    Thanks.

    Pl45m4P 1 Reply Last reply
    0
    • C Offline
      C Offline
      CHPOG
      wrote on last edited by
      #7

      Thanks @SGaist. This is solved by change compiler and used Mingw instead of MSVC.

      1 Reply Last reply
      0
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @CHPOG said in Link error in test unit with QOBJECT macro:

        ~RS232UniWheel();

        Did you actually implement this ctor?

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        C 1 Reply Last reply
        1
        • C CHPOG

          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_H
          
          

          All these are quite simple usage of Qt code.

          If anyone has an idea ??

          Thanks.

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by Pl45m4
          #3

          @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 QtSerialPort included 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


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          1 Reply Last reply
          2
          • Christian EhrlicherC Christian Ehrlicher

            @CHPOG said in Link error in test unit with QOBJECT macro:

            ~RS232UniWheel();

            Did you actually implement this ctor?

            C Offline
            C Offline
            CHPOG
            wrote on last edited by CHPOG
            #4

            @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.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #5

              Hi,

              What compiler are you using ?
              What version of Qt are you building your test with ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • C Offline
                C Offline
                CHPOG
                wrote on last edited by CHPOG
                #6

                @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);
                }
                
                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  CHPOG
                  wrote on last edited by
                  #7

                  Thanks @SGaist. This is solved by change compiler and used Mingw instead of MSVC.

                  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