Results 1 to 8 of 8

Thread: QMetaObject::connectSlotsByName: No matching signal for ...

  1. #1
    Join Date
    Mar 2010
    Location
    Auckland, NZ
    Posts
    121
    Thanks
    9
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QMetaObject::connectSlotsByName: No matching signal for ...

    I use Qt Creator to design my GUI. Everything seems to be working as I expect, but when the program executes it generates some error messages (which do not cause it to terminate). Here is an example of one category of error message:

    In Qt Creator I have created a radio button, with objectName rbut_ACTIVATION_MODE_0. I have set up the signal toggled(bool) to the receiver MainWindow, to slot on_activation_mode_toggled(bool). In mainwindow.cpp I have code for
    void MainWindow:n_activation_mode_toggled(bool) which is declared as a private slot.
    After the program has executed I see this message:

    QMetaObject::connectSlotsByName: No matching signal for on_activation_mode_toggled(bool)

    Perhaps somebody can explain what this means.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QMetaObject::connectSlotsByName: No matching signal for ...

    You object name does not match the slot name anymore.
    This is why it is really recommended to not use that name based auto connection mechanism at all!

    Just connect the widget to the slot as usual and you won't run into such problems anymore, even when object names change again (because then you will get a compiler error directly at the connect statement, allowing you to fix it right away).

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    gib (27th October 2013)

  4. #3
    Join Date
    Mar 2010
    Location
    Auckland, NZ
    Posts
    121
    Thanks
    9
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QMetaObject::connectSlotsByName: No matching signal for ...

    Thanks! I hadn't realized the need to make the object and slot names match like this. What puzzles me is that the program works even though there is an error message. The signal gets sent to the slot. How does this work?

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QMetaObject::connectSlotsByName: No matching signal for ...

    Quote Originally Posted by gib View Post
    Thanks! I hadn't realized the need to make the object and slot names match like this.
    Yes, that is the "trade-off" for the "automatism" of this form of connect. Which is why any professional Qt developer will recommend not to use it (too fragile)

    Quote Originally Posted by gib View Post
    What puzzles me is that the program works even though there is an error message. The signal gets sent to the slot. How does this work?
    I don't know, it should not work if the connect fails.

    Check if there is an explicit connect somewhere. I.e. maybe someone change the object name, "fixed" the connect by doing an explicit connect(), but Qt is still trying to do the name based connect.

    Cheers,
    _

  6. #5
    Join Date
    Mar 2010
    Location
    Auckland, NZ
    Posts
    121
    Thanks
    9
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QMetaObject::connectSlotsByName: No matching signal for ...

    I think I am not relying on "automatism", because I use "Edit Signals/Slots" to explicitly connect the button via the toggled() signal to the slot. This is what appears in the .ui file:

    <sender>rbut_ACTIVATION_MODE_0</sender>
    <signal>toggled(bool)</signal>
    <receiver>MainWindow</receiver>
    <slot>on_rbut_ACTIVATION_MODE_toggled(bool)</slot>

    I had not realized that just having the slot named in the list in the UI is sufficient if the name matches - of course this must be the automatism you refer to, which I was previously unaware of. It seems that this signal does indeed get through, but Qt's error checking still tells me that there is no signal with a matching name for slot on_rbut_ACTIVATION_MODE_toggled(bool), i.e. no automatic connection.
    Last edited by gib; 28th October 2013 at 22:07.

  7. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QMetaObject::connectSlotsByName: No matching signal for ...

    The automatism works on slot name patterns. It sees a slot starting with "on_" and tries to find a member and signal that matches the rest.

    You could rename the slot so that the pattern matching fails, e.g. name it "onActivationModeToggled" or something like that.

    Cheers,
    _

  8. The following user says thank you to anda_skoa for this useful post:

    loccus (19th October 2016)

  9. #7
    Join Date
    Mar 2010
    Location
    Auckland, NZ
    Posts
    121
    Thanks
    9
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QMetaObject::connectSlotsByName: No matching signal for ...

    OK, thanks.

  10. #8
    Join Date
    Nov 2013
    Posts
    1
    Qt products
    Qt3
    Platforms
    MacOS X

    Default Re: QMetaObject::connectSlotsByName: No matching signal for ...

    I prefer to read this kind of nice stuff. The quality of content is fine and the conclusion is good. Thanks for the post.

Similar Threads

  1. connectSlotsByName isn't working
    By scarleton in forum Newbie
    Replies: 1
    Last Post: 9th October 2010, 13:52
  2. connectSlotsByName and clicked()
    By becrux in forum Qt Programming
    Replies: 5
    Last Post: 2nd December 2009, 08:05
  3. How to use QMetaObject::invokeMethod?
    By niko in forum Qt Programming
    Replies: 3
    Last Post: 26th January 2008, 17:02
  4. Replies: 2
    Last Post: 8th November 2007, 21:23
  5. Reg - QMetaObject Error
    By suresh in forum Newbie
    Replies: 12
    Last Post: 4th September 2006, 23:27

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.