QWidget signal autoconnection problem
I have a quite big project and recently I recognized, that some of the widget slots started to not work. I mean, that I created a pushbutton for which I created the clicked slot by using the Designer (connect to slot menu), which worked, but now some of these controls stopped working. To work around, I need to explicitly connect them in the constructor, but that is not a safe thing, as this misbehavior is not always happening, and I cannot find any clue to decide whether I need to connect a slot explicitly or it will work automatically. Currently I have 27 slots in one of the strangely behavioring forms. From them the first 6 do not connect automatically, and I get a runtime warning (QMetaObject::connectSlotsByName: No matching signal for on_captureCameraPushButton_clicked()) for them. As it can be seen, the slot is named the standard way. I have the captureCameraPushButton widget in my form, which is a QPushButton. Some other pushbuttons work perfectly in the same form. If I comment out the first 6 slots from the header and the source file, then the other slots work fine, and no warning is given. I generated all these slots the same way using the Designer. If I try to generate one again, no new slot is created, but the cursor jumps to the already existing slot.
I am using Qt 5.9.0 on Linux 64. In former Qt versions I did not experience anything similar.
How could I fix this, so that these slots are connected automatically and reliably?
Might be a silly question but how do you know they are not working as expected ?
@SGaist The runtime message complaining about the signal indicates that it cannot connect. The slots are indeed not executed, which I checked with a qDebug message, that did not appeared in the output, and by using gdb too, in which case the breakpoint in the slot did not hit.
The runtime message complaining about the signal indicates that it cannot connect
It would be helpful to see this message
QMetaObject::connectSlotsByName: No matching signal for on_togglePlcPushButton_toggled(bool)
As I said, the togglePlcPushButton QPushButton exists in the form. The same pattern is working fine for some other QWidgets in the same form. The working and not working slots are both connected by the Designer (Go to slot menu).
Is it possible to grab the code somewhere to inspect it ?
Or for you to create a minimal compilable example showing that behaviour ?
is it the
"QMetaObject::connectSlotsByName: No matching signal for ..." error ? (yep, you posted while writing :)
Did you rename the widgets ?
It works by the naming of the widgets
so if you rename the button AFTER you made the slot, there is no match anymore.
the rule is
If you didnt do any of that, then please delete your build folder and rebuild
So if want to you use auto connection, you should name the widgets as you want before hooking up slots.
Not only renaming: if you switched from using clicked() signal to toggled() signal, this may fail as well.
Like rename the slot to _toggled() or in what way switch ?
or like adding the new slot and delete old and it complains?
Deleting build folder should cure that or you mean something else?
I tried to create a smaller project, but that does not show that behavior, all those slots are connected and called.
I made several rebuilds, deleted all the generated files, etc, but that did not help. I used the Designer to generate those slots, and the Designer took care of the proper slot names, and I triplechecked, that the QWidgets exist in the form. I will try to switch to Qt 5.9.1, but I do not hope much from that.
I would drop the use of QtCreators
I got screwed a few times when I started with it. But since then changed to defining all my connects by hand using Qt5 syntax when possible. That way, the project won't compile if I/or something messed by Signals/Slots up.
Ok, so rebuilding with Qt 5.9.1 did not help.
However it seems even more mysterious. My form's layout is a grid layout, and I have several grid layouts in it. The buttons are in those grid layouts. Now I moved one of my faulty button to the outermost grid layout. The slot now connected automatically, but now I have 13 unconnected slots including the 5, that were faulty previously. The 6th (which I moved out from an inner grid layout) now works perfectly.
@J.Hilk Yes, that is a final solution, however using the automatic connection feature is very comfortable and it worked for me for several years. Only recently started to fail. But eventually I will be forced to connect them manually.
@SGaist Maybe via teamviewer?
If I move that button back to its original place either by dragging and dropping or by undoing the previous edit, there are still 13 unconnected slots. By undoing I expected to get back at least the original behavior. Something non-deterministic happens here?
Furthermore if I set a stylesheet for a faulty button in the designer (red background), it appears correctly in the preview with the modified stylesheet, but it does not have any influence on the widget when I run the program. If I set the same stylesheet in the code, it appears correctly even when I run it. I suppose this is in connection with the above not connected slots, although I do not understand it, and I have no idea, what the cause could be.