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. signals in a derived class ?
Forum Updated to NodeBB v4.3 + New Features

signals in a derived class ?

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 5 Posters 929 Views 3 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by
    #1

    I have a base class which has signals:

    class MsgDecoder : public QObject
    {
       Q_OBJECT
     
    private:
       QString mstrMsgType;
       eDestination meDest;
       static tMsgTypesMap msmpMsgTypes;
     
    public:
       MsgDecoder(const QString& crstrMsgType, const eDestination ceDest);
     
       virtual bool blnDecode(const QJsonObject& crobjMsg) = 0;
       QString cstrMsgType() const { return mstrMsgType; }
       static bool blnDecodeMsgByType(const QString& crstrMsgType,
                                      const QJsonObject& crobjMsg);
       eDestination eDest() { return meDest; }
       static eDestination getDestFromMsg(const QJsonObject& crobjMsg);
       static eDestination getDestFromMsg(const QString& crstrMsg);
       static eDestination getDestFromMsgType(const char* cpszMsgType);
     
    signals:
       void error(const QString& crstrErrorMsg);  
    };
    

    I have several working derived classes based on the above, today I've added a new class:

    class SessionMsgRestarted : public MsgDecoder
    {
    public:
        SessionMsgRestarted();
        virtual bool blnDecode(const QJsonObject &crobjMsg);
     
    signals:
        void traineeRestarted(const QString& crstrMACaddress);
    };
    

    However I'm getting very strange compilation errors which I cannot see what the cause is:

    sessionmsg.obj:-1: error: LNK2019: unresolved external symbol "public: void __thiscall SessionMsgRestarted::traineeRestarted(class QString const &)" (?traineeRestarted@SessionMsgRestarted@@QAEXABVQString@@@Z) referenced in function "public: virtual bool __thiscall SessionMsgRestarted::blnDecode(class QJsonObject const &)" (?blnDecode@SessionMsgRestarted@@UAE_NABVQJsonObject@@@Z)
    debug\trngServer.exe:-1: error: LNK1120: 1 unresolved externals
    

    I'm just wondering is there any restriction or limitation on signals in derived classes?

    Kind Regards,
    Sy

    JonBJ Pl45m4P 2 Replies Last reply
    0
    • SPlattenS SPlatten

      I have a base class which has signals:

      class MsgDecoder : public QObject
      {
         Q_OBJECT
       
      private:
         QString mstrMsgType;
         eDestination meDest;
         static tMsgTypesMap msmpMsgTypes;
       
      public:
         MsgDecoder(const QString& crstrMsgType, const eDestination ceDest);
       
         virtual bool blnDecode(const QJsonObject& crobjMsg) = 0;
         QString cstrMsgType() const { return mstrMsgType; }
         static bool blnDecodeMsgByType(const QString& crstrMsgType,
                                        const QJsonObject& crobjMsg);
         eDestination eDest() { return meDest; }
         static eDestination getDestFromMsg(const QJsonObject& crobjMsg);
         static eDestination getDestFromMsg(const QString& crstrMsg);
         static eDestination getDestFromMsgType(const char* cpszMsgType);
       
      signals:
         void error(const QString& crstrErrorMsg);  
      };
      

      I have several working derived classes based on the above, today I've added a new class:

      class SessionMsgRestarted : public MsgDecoder
      {
      public:
          SessionMsgRestarted();
          virtual bool blnDecode(const QJsonObject &crobjMsg);
       
      signals:
          void traineeRestarted(const QString& crstrMACaddress);
      };
      

      However I'm getting very strange compilation errors which I cannot see what the cause is:

      sessionmsg.obj:-1: error: LNK2019: unresolved external symbol "public: void __thiscall SessionMsgRestarted::traineeRestarted(class QString const &)" (?traineeRestarted@SessionMsgRestarted@@QAEXABVQString@@@Z) referenced in function "public: virtual bool __thiscall SessionMsgRestarted::blnDecode(class QJsonObject const &)" (?blnDecode@SessionMsgRestarted@@UAE_NABVQJsonObject@@@Z)
      debug\trngServer.exe:-1: error: LNK1120: 1 unresolved externals
      

      I'm just wondering is there any restriction or limitation on signals in derived classes?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @SPlatten
      Your class SessionMsgRestarted does not specify Q_OBJECT. Even though derived from a class which does, I believe you must specify this to declare a signal in any class? And then don't forget to do a change-underpants rebuild when you add that macro to an existing previously-compiled class :)

      SPlattenS 1 Reply Last reply
      3
      • M Offline
        M Offline
        mchinand
        wrote on last edited by
        #3

        I think you still need to have a Q_OBJECT line in your derived class

        1 Reply Last reply
        2
        • SPlattenS SPlatten

          I have a base class which has signals:

          class MsgDecoder : public QObject
          {
             Q_OBJECT
           
          private:
             QString mstrMsgType;
             eDestination meDest;
             static tMsgTypesMap msmpMsgTypes;
           
          public:
             MsgDecoder(const QString& crstrMsgType, const eDestination ceDest);
           
             virtual bool blnDecode(const QJsonObject& crobjMsg) = 0;
             QString cstrMsgType() const { return mstrMsgType; }
             static bool blnDecodeMsgByType(const QString& crstrMsgType,
                                            const QJsonObject& crobjMsg);
             eDestination eDest() { return meDest; }
             static eDestination getDestFromMsg(const QJsonObject& crobjMsg);
             static eDestination getDestFromMsg(const QString& crstrMsg);
             static eDestination getDestFromMsgType(const char* cpszMsgType);
           
          signals:
             void error(const QString& crstrErrorMsg);  
          };
          

          I have several working derived classes based on the above, today I've added a new class:

          class SessionMsgRestarted : public MsgDecoder
          {
          public:
              SessionMsgRestarted();
              virtual bool blnDecode(const QJsonObject &crobjMsg);
           
          signals:
              void traineeRestarted(const QString& crstrMACaddress);
          };
          

          However I'm getting very strange compilation errors which I cannot see what the cause is:

          sessionmsg.obj:-1: error: LNK2019: unresolved external symbol "public: void __thiscall SessionMsgRestarted::traineeRestarted(class QString const &)" (?traineeRestarted@SessionMsgRestarted@@QAEXABVQString@@@Z) referenced in function "public: virtual bool __thiscall SessionMsgRestarted::blnDecode(class QJsonObject const &)" (?blnDecode@SessionMsgRestarted@@UAE_NABVQJsonObject@@@Z)
          debug\trngServer.exe:-1: error: LNK1120: 1 unresolved externals
          

          I'm just wondering is there any restriction or limitation on signals in derived classes?

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

          @SPlatten said in signals in a derived class ?:

          class SessionMsgRestarted : public MsgDecoder
          {
          public:

          No Q_OBJECT macro in derived class?!

          Edit:

          Hahah @JonB @mchinand :)
          3 instant replies


          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
          1
          • JonBJ JonB

            @SPlatten
            Your class SessionMsgRestarted does not specify Q_OBJECT. Even though derived from a class which does, I believe you must specify this to declare a signal in any class? And then don't forget to do a change-underpants rebuild when you add that macro to an existing previously-compiled class :)

            SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by
            #5

            @JonB , thank you, I thought you had the solution, but now I get:

            sessionmsg.obj:-1: error: LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall SessionMsgRestarted::metaObject(void)const " (?metaObject@SessionMsgRestarted@@UBEPBUQMetaObject@@XZ)
            sessionmsg.obj:-1: error: LNK2001: unresolved external symbol "public: virtual void * __thiscall SessionMsgRestarted::qt_metacast(char const *)" (?qt_metacast@SessionMsgRestarted@@UAEPAXPBD@Z)
            sessionmsg.obj:-1: error: LNK2001: unresolved external symbol "public: virtual int __thiscall SessionMsgRestarted::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@SessionMsgRestarted@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
            sessionmsg.obj:-1: error: LNK2019: unresolved external symbol "public: void __thiscall SessionMsgRestarted::traineeRestarted(class QString const &)" (?traineeRestarted@SessionMsgRestarted@@QAEXABVQString@@@Z) referenced in function "public: virtual bool __thiscall SessionMsgRestarted::blnDecode(class QJsonObject const &)" (?blnDecode@SessionMsgRestarted@@UAE_NABVQJsonObject@@@Z)
            debug\trngServer.exe:-1: error: LNK1120: 4 unresolved externals
            

            Kind Regards,
            Sy

            JonBJ 1 Reply Last reply
            0
            • SPlattenS SPlatten

              @JonB , thank you, I thought you had the solution, but now I get:

              sessionmsg.obj:-1: error: LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall SessionMsgRestarted::metaObject(void)const " (?metaObject@SessionMsgRestarted@@UBEPBUQMetaObject@@XZ)
              sessionmsg.obj:-1: error: LNK2001: unresolved external symbol "public: virtual void * __thiscall SessionMsgRestarted::qt_metacast(char const *)" (?qt_metacast@SessionMsgRestarted@@UAEPAXPBD@Z)
              sessionmsg.obj:-1: error: LNK2001: unresolved external symbol "public: virtual int __thiscall SessionMsgRestarted::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@SessionMsgRestarted@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
              sessionmsg.obj:-1: error: LNK2019: unresolved external symbol "public: void __thiscall SessionMsgRestarted::traineeRestarted(class QString const &)" (?traineeRestarted@SessionMsgRestarted@@QAEXABVQString@@@Z) referenced in function "public: virtual bool __thiscall SessionMsgRestarted::blnDecode(class QJsonObject const &)" (?blnDecode@SessionMsgRestarted@@UAE_NABVQJsonObject@@@Z)
              debug\trngServer.exe:-1: error: LNK1120: 4 unresolved externals
              
              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @SPlatten
              And did you do the change-underpants rebuild like I said not to forget? That means: delete the build output directory's files and rebuild.....

              SPlattenS 1 Reply Last reply
              4
              • JonBJ JonB

                @SPlatten
                And did you do the change-underpants rebuild like I said not to forget? That means: delete the build output directory's files and rebuild.....

                SPlattenS Offline
                SPlattenS Offline
                SPlatten
                wrote on last edited by
                #7

                @JonB , actually, I just did a clean, then rebuild all and now its all good, thank you!

                Kind Regards,
                Sy

                JonBJ 1 Reply Last reply
                1
                • SPlattenS SPlatten

                  @JonB , actually, I just did a clean, then rebuild all and now its all good, thank you!

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #8

                  @SPlatten
                  Basically, if you add (or presumably also remove) Q_OBJECT to a class which you previously compiled without it, you need to force a full rebuild every time. I do it via deleting all the files as I thought some peeps say rebuild alone is not enough, but I don't know. And any time I get a Qt link error which I don't expect/impenetrable message and looks vaguely like it might be related to objects/metas etc. I do that before I start wondering if I have made some other mistake :)

                  KroMignonK Pl45m4P 2 Replies Last reply
                  1
                  • JonBJ JonB

                    @SPlatten
                    Basically, if you add (or presumably also remove) Q_OBJECT to a class which you previously compiled without it, you need to force a full rebuild every time. I do it via deleting all the files as I thought some peeps say rebuild alone is not enough, but I don't know. And any time I get a Qt link error which I don't expect/impenetrable message and looks vaguely like it might be related to objects/metas etc. I do that before I start wondering if I have made some other mistake :)

                    KroMignonK Offline
                    KroMignonK Offline
                    KroMignon
                    wrote on last edited by
                    #9

                    @JonB said in signals in a derived class ?:

                    Basically, if you add (or presumably also remove) Q_OBJECT to a class which you previously compiled without it, you need to force a full rebuild every time. I do it via deleting all the files as I thought some peeps say rebuild alone is not enough, but I don't know. And any time I get a Qt link error which I don't expect/impenetrable message and looks vaguely like it might be related to objects/metas etc. I do that before I start wondering if I have made some other mistake :)

                    When changing Q_OBJECT and/or signals/slots, you have to rerun the MOC. When you are lucky QtCreator detect those changes and rerun himself the MOC.

                    With qmake based projects, you can rerun qmake which will rerun the MOC and update the makefile and then rebuild the project.

                    Width cmake projects, I don't know, I have no experience.

                    At least, if nothing works, deleting the build directory is the solution which always works ;)

                    It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                    1 Reply Last reply
                    0
                    • JonBJ JonB

                      @SPlatten
                      Basically, if you add (or presumably also remove) Q_OBJECT to a class which you previously compiled without it, you need to force a full rebuild every time. I do it via deleting all the files as I thought some peeps say rebuild alone is not enough, but I don't know. And any time I get a Qt link error which I don't expect/impenetrable message and looks vaguely like it might be related to objects/metas etc. I do that before I start wondering if I have made some other mistake :)

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

                      @JonB said in signals in a derived class ?:

                      I do that before I start wondering if I have made some other mistake :)

                      "Clean & (Re-)Build" and "qmake" is like being root on Linux or rebooting your Windows machine :-)
                      Fixes a lot of errors ;-)


                      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
                      1

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved