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. Signal & Slot weard error (Qt 5.7.1)

Signal & Slot weard error (Qt 5.7.1)

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 3.7k 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.
  • michalosM Offline
    michalosM Offline
    michalos
    wrote on last edited by
    #1

    Hi,
    can someone tell my why when I use this:

        connect(window,&MainWindow::sendHistoryRequestWithMarker,pbxConneciton,&PBXConnect::getHistoryCallUpdates);
    

    I get an compiler error:
    C2664: 'QMetaObject::Connection QObject::connect(const QObject *,const char *,const char ,Qt::ConnectionType) const': cannot convert argument 2 from 'void (__cdecl MainWindow:: )(QString &)' to 'const char *'

    , and this:

        connect(window,SIGNAL(sendHistoryRequestWithMarker(QString&)),pbxConneciton,SLOT(getHistoryCallUpdates(QString&)));
    

    emits an error:
    QObject::connect: Cannot queue arguments of type 'QString&'
    (Make sure 'QString&' is registered using qRegisterMetaType().)

    one line below I have :

        connect(window,&MainWindow::mainwindowSendUpdate_REQ,pbxConneciton,&PBXConnect::sendUpdate_REQ);
    

    that works perfectly?

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

      could you show us the signature of MainWindow::sendHistoryRequestWithMarker and PBXConnect::getHistoryCallUpdates? are you overloading any of these functions?

      "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
      • michalosM Offline
        michalosM Offline
        michalos
        wrote on last edited by michalos
        #3

        Yes, I have :

            void getHistoryCallUpdates();
        ///and
            void getHistoryCallUpdates(QString &);
        
        mrjjM 1 Reply Last reply
        0
        • michalosM Offline
          michalosM Offline
          michalos
          wrote on last edited by
          #4

          I've changed the functions name.

          now, when I send the signal I get:

          QObject::connect: Cannot queue arguments of type 'QString&'
          (Make sure 'QString&' is registered using qRegisterMetaType().)

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

            ok, 2 more things:

            • what's the signature of MainWindow::sendHistoryRequestWithMarker
            • what version of Qt are you using?

            "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
            • michalosM michalos

              Yes, I have :

                  void getHistoryCallUpdates();
              ///and
                  void getHistoryCallUpdates(QString &);
              
              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @michalos
              Hi
              Using the new syntax , you must use cast when you have a overloaded signal.
              ( same name, different paramters)

              lIke in

              connect(mySpinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), mySlider, &QSlider::setValue);

              https://wiki.qt.io/New_Signal_Slot_Syntax

              VRoninV 1 Reply Last reply
              2
              • mrjjM mrjj

                @michalos
                Hi
                Using the new syntax , you must use cast when you have a overloaded signal.
                ( same name, different paramters)

                lIke in

                connect(mySpinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), mySlider, &QSlider::setValue);

                https://wiki.qt.io/New_Signal_Slot_Syntax

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

                @mrjj said in Signal & Slot weard error (Qt 5.7.1):

                you must use cast when you have a overloaded signal

                or for Qt>=5.7 qOverload

                Edit:
                Are you using Qt::QueuedConnection (i.e. sender and receiver are in 2 different threads)?
                Do you really mean to pass a non-const QString reference?

                "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
                • michalosM Offline
                  michalosM Offline
                  michalos
                  wrote on last edited by
                  #8

                  @VRonin @mrjj
                  That's helpful to know.

                  But renaming the Signal and the Slot does not solve the problem.
                  I still get the error :
                  QObject::connect: Cannot queue arguments of type 'QString&'
                  (Make sure 'QString&' is registered using qRegisterMetaType().)

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

                    Could you answer all pending questions?

                    • Are you using Qt::QueuedConnection (i.e. sender and receiver are in 2 different threads)?
                    • Do you really mean to pass a non-const QString reference?
                    • what's the signature of MainWindow::sendHistoryRequestWithMarker
                    • what version of Qt are you using?

                    "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
                    • michalosM Offline
                      michalosM Offline
                      michalos
                      wrote on last edited by
                      #10

                      @VRonin

                      • Yes, I am using Qt::QueuedConnection
                      • Can You tell me why passing a non-const QString reference is a problem?
                      • signature (if I understand correctly) is:
                      void sendHistoryRequestWithMarkerMain(QString &);
                      
                      • I am using Qt 5.7.1 (MSVC 2015 64 bit)

                      Changing the QString & to const QString & did help, but I would appreciate If You could explain me why (or point me in the right direction).

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

                        @michalos said in Signal & Slot weard error (Qt 5.7.1):

                        Can You tell me why passing a non-const QString reference is a problem?

                        Because that string could be modified on the other side so you cannot store "a copy of it" in a queue

                        "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
                        2

                        • Login

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