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. Unresolved external symbol when connecting with new syntax
Qt 6.11 is out! See what's new in the release blog

Unresolved external symbol when connecting with new syntax

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 4 Posters 6.3k Views 1 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.
  • M Offline
    M Offline
    Mwoua
    wrote on last edited by Mwoua
    #1

    Hello,

    I have a class that inherits from QLineEdit to implement clicked signal :

    #if defined(LD_LIBRARY)
    #  define LD_DLL Q_DECL_EXPORT
    #else
    #  define LD_DLL Q_DECL_IMPORT
    #endif
    
    class LdLineEdit: public QLineEdit
    {
        Q_OBJECT
    public:
        LD_DLL explicit LdLineEdit( QWidget *aParent = nullptr );
    signals:
        LD_DLL void LdClicked();
    protected:
        void mouseReleaseEvent(QMouseEvent *){emit LdClicked();}
    }
    

    And when I try to connect to this signal with the new syntax :

    connect(&mLESerial, &LdLineEdit::LdClicked,this,&PrReportViewer::LESerialTextEdited);
    

    I have this error :

    PrReportViewer.obj:-1: error: LNK2001: unresolved external symbol "public: static struct QMetaObject const LdLineEdit::staticMetaObject" (?staticMetaObject@LdLineEdit@@2UQMetaObject@@B)
    

    However, if i use the old syntax :

    connect( &mLESerial, SIGNAL( LdClicked() ), this, SLOT( LESerialTextEdited() ) ) ;
    

    it works (it compiles, and its actually connected)

    I need the new syntax to plug a Lambda instead of that slot, and it would be nice to understand anyway.

    VRoninV 1 Reply Last reply
    1
    • M Mwoua

      Hello,

      I have a class that inherits from QLineEdit to implement clicked signal :

      #if defined(LD_LIBRARY)
      #  define LD_DLL Q_DECL_EXPORT
      #else
      #  define LD_DLL Q_DECL_IMPORT
      #endif
      
      class LdLineEdit: public QLineEdit
      {
          Q_OBJECT
      public:
          LD_DLL explicit LdLineEdit( QWidget *aParent = nullptr );
      signals:
          LD_DLL void LdClicked();
      protected:
          void mouseReleaseEvent(QMouseEvent *){emit LdClicked();}
      }
      

      And when I try to connect to this signal with the new syntax :

      connect(&mLESerial, &LdLineEdit::LdClicked,this,&PrReportViewer::LESerialTextEdited);
      

      I have this error :

      PrReportViewer.obj:-1: error: LNK2001: unresolved external symbol "public: static struct QMetaObject const LdLineEdit::staticMetaObject" (?staticMetaObject@LdLineEdit@@2UQMetaObject@@B)
      

      However, if i use the old syntax :

      connect( &mLESerial, SIGNAL( LdClicked() ), this, SLOT( LESerialTextEdited() ) ) ;
      

      it works (it compiles, and its actually connected)

      I need the new syntax to plug a Lambda instead of that slot, and it would be nice to understand anyway.

      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      What type is mLESerial? LdLineEdit or LdLineEdit*?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mwoua
        wrote on last edited by
        #3

        LdLineEdit

        Taz742T 1 Reply Last reply
        0
        • M Mwoua

          LdLineEdit

          Taz742T Offline
          Taz742T Offline
          Taz742
          wrote on last edited by
          #4

          @Mwoua
          And What is LdLineEdit ?

          Do what you want.

          M 1 Reply Last reply
          0
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            Strange error. replace private slots: with protected: btw, the event is not a slot. Also add a constructor or you'll potentially break parent/child dependency.

            Last question, what is LD_DLL?

            class LdLineEdit: public QLineEdit
            {
                Q_OBJECT
            Q_DISABLE_COPY(LdLineEdit)
            public:
            LdLineEdit(QWidget* parent = Q_NULLPTR)
            :QLineEdit(parent)
            {}
            signals:
                LD_DLL void LdClicked();
            protected:
                void mouseReleaseEvent(QMouseEvent *){emit LdClicked();}
            }
            

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            1
            • Taz742T Taz742

              @Mwoua
              And What is LdLineEdit ?

              M Offline
              M Offline
              Mwoua
              wrote on last edited by Mwoua
              #6

              @Taz742
              See first post

              @VRonin
              The constructor is there in my class, I forgot it because I wanted to simplify (I'll edit my first post)

              The macro is :

              #if defined(LD_LIBRARY)
              #  define LD_DLL Q_DECL_EXPORT
              #else
              #  define LD_DLL Q_DECL_IMPORT
              #endif
              

              LdLineEdit is in a dll that I use in my other function

              Same issue with the function in protected.

              EDIT : it might be linked to the dll, if I do this inside a function of LdLineEdit :

              connect( this, &LdLineEdit::LdClicked, this, &LdLineEdit::ThisValueChanged);
              

              It compiles (ThisValueChanged is private slot of LdLineEdit)

              VRoninV kshegunovK 2 Replies Last reply
              0
              • M Mwoua

                @Taz742
                See first post

                @VRonin
                The constructor is there in my class, I forgot it because I wanted to simplify (I'll edit my first post)

                The macro is :

                #if defined(LD_LIBRARY)
                #  define LD_DLL Q_DECL_EXPORT
                #else
                #  define LD_DLL Q_DECL_IMPORT
                #endif
                

                LdLineEdit is in a dll that I use in my other function

                Same issue with the function in protected.

                EDIT : it might be linked to the dll, if I do this inside a function of LdLineEdit :

                connect( this, &LdLineEdit::LdClicked, this, &LdLineEdit::ThisValueChanged);
                

                It compiles (ThisValueChanged is private slot of LdLineEdit)

                VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by
                #7

                @Mwoua said in Unresolved external symbol when connecting with new syntax:

                LdLineEdit is in a dll

                BINGO!
                you should export the whole class

                class LD_DLL LdLineEdit: public QLineEdit
                {
                    Q_OBJECT
                Q_DISABLE_COPY(LdLineEdit)
                public:
                LdLineEdit(QWidget* parent = Q_NULLPTR)
                :QLineEdit(parent)
                {}
                signals:
                    void LdClicked();
                protected:
                    void mouseReleaseEvent(QMouseEvent *){emit LdClicked();}
                }
                
                

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                1 Reply Last reply
                4
                • M Mwoua

                  @Taz742
                  See first post

                  @VRonin
                  The constructor is there in my class, I forgot it because I wanted to simplify (I'll edit my first post)

                  The macro is :

                  #if defined(LD_LIBRARY)
                  #  define LD_DLL Q_DECL_EXPORT
                  #else
                  #  define LD_DLL Q_DECL_IMPORT
                  #endif
                  

                  LdLineEdit is in a dll that I use in my other function

                  Same issue with the function in protected.

                  EDIT : it might be linked to the dll, if I do this inside a function of LdLineEdit :

                  connect( this, &LdLineEdit::LdClicked, this, &LdLineEdit::ThisValueChanged);
                  

                  It compiles (ThisValueChanged is private slot of LdLineEdit)

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by kshegunov
                  #8

                  Export the whole class, not only a handful of methods.

                  Edit: Crossposted with our Ronin, but it happens. ;)

                  Read and abide by the Qt Code of Conduct

                  1 Reply Last reply
                  4
                  • M Offline
                    M Offline
                    Mwoua
                    wrote on last edited by
                    #9

                    Ok, is there a rule to export a whole class or just a part of it?

                    kshegunovK 1 Reply Last reply
                    0
                    • M Mwoua

                      Ok, is there a rule to export a whole class or just a part of it?

                      kshegunovK Offline
                      kshegunovK Offline
                      kshegunov
                      Moderators
                      wrote on last edited by kshegunov
                      #10

                      The rule is you need to export Qt's methods and variables from your class - the ones Q_OBJECT introduces (in this case the staticMetaObject, see your linker error in the OP), so when working with QObjects always export the whole class.

                      Read and abide by the Qt Code of Conduct

                      1 Reply Last reply
                      4
                      • M Offline
                        M Offline
                        Mwoua
                        wrote on last edited by
                        #11

                        Thanks for the help !

                        kshegunovK 1 Reply Last reply
                        0
                        • M Mwoua

                          Thanks for the help !

                          kshegunovK Offline
                          kshegunovK Offline
                          kshegunov
                          Moderators
                          wrote on last edited by
                          #12

                          No problem. As to why it works with the old syntax - it works because there's no compile time checking and all is done in runtime.

                          Read and abide by the Qt Code of Conduct

                          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