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::on_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.
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,
_
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?
Re: QMetaObject::connectSlotsByName: No matching signal for ...
Quote:
Originally Posted by
gib
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
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,
_
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.
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,
_
Re: QMetaObject::connectSlotsByName: No matching signal for ...
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.