Connecting custom slots whith signals using Qt Designer
-
Hi,
I defined some slots in form.cpp, can I connecting them with signals using Qt Designer (i.e. by selecting them from a list) ? -
Thanks, the syntax is as follows :
@void on_<object name>_<signal name>(<signal parameters>);@
but if I have to connect it with multiple signals what's the naming?
-
You cannot do that automatically, you will have to do that manually from code. Note that even for the autoconnect syntax above, there is a snag. The object names from designer by default contain underscores ("pushbutton_2"), but those get in the way of the auto connect magic. It is a good idea to rename widgets on your forms to something more informative anyway, but you will have to do that if you want to use the autoconnect features.
Personally, I don't really like that feature at all, and prefer to have all connections made explicitly to methods that I can then give a proper name. Sometimes onMyButtonClicked may be an appropriate name for a slot, but most often I want to describe the actual action (moveToAdvancedState) instead of describing what triggered its execution. Also, the mechanism promotes non-Qt like naming for methods. The Qt API uses camel casing for method names, not underscores.
-
Thank you very much for these interesting informations.
I think that connecting visually a custom slot with one or more custom signals without using autoconnect syntax for naming is very innovative feature that it can be added easily by a simple parsing of the .h file. -
No, it cannot be added easily. Designer does not know of the use of your form.ui file at all - which is a good thing™. You might want to use it in a QUiLoader which doesn't have that surrounding class, etc. It would only work with a very limited use case of the forms and I'm not convinced whether it's worth the effort.