"go to slot" vs coded signal/slot connection
-
Hello everyone,
Understanding that the message "Slots named on_foo_bar are error prone" warns me of potential future link errors, I've tried to make the link in question hard in the code using the 'connect' command:However, I still get the same warning "Slots named...", so I don't understand what I've gained by adding this code (as long as it's correct)
Thank you for your feedback
-
@MortyMars said in "go to slot" vs coded signal/slot connection:
However, I still get the same warning "Slots named...", so I don't understand what I've gained by adding this code (as long as it's correct)
Because the
on_<objectname>_<signal>
syntax, as used by Qt's auto-connect, can be broken very easily.Here is a similar topic, where this "go-to-slot"-connection way was discussed with a user.
-
Hi @Pl45m4
Thank you for your reply and the link, which will help me to understand this signal-slot process better.
With this connection through the code, I'll be able to rename my objects while preserving their bindings, for example, isn't that right?
Regarding the warning message, I've managed to remove it by moving the definition of the method concerned from the "private slots:" section to "private:"...
-
@MortyMars said in "go to slot" vs coded signal/slot connection:
With this connection through the code, I'll be able to rename my objects while preserving their bindings, for example, isn't that right?
You probably can, but honestly if you use Qt a bit most people just don't bother with the hassle. Connecting from Designer is not worth that much, we all use our own explicit
connect()
statements instead, and do not use connect slots by name. Up to you.Regarding the warning message, I've managed to remove it by moving the definition of the method concerned from the "private slots:" section to "private:"...
IIRC,
slots
is#define
d to nothing/empty. Soprivate slots:
is already justprivate
. Hence I don't know what you did or think you achieved. Maybe it's just some moc message. There you are. -
@MortyMars
Well it seems to me that's just because now you are not telling it that it's a slot at all it doesn't warn you about the way it's namedon_....
being "error prone". It's not an error, it's a diagnostic warning from clazy. If you don't have theconnectSlotsByName()
call (insetupUi()
, I think, and I believe it can be turned off, which most of us do, or even if that's not possible we just don't name slots thaton_...
way, which Designer does, so it doesn't arise). I would rather have them marked asslots
if they are slots, but not use the auto-connect-by-name. But it's up to you.What you should not do is on the one hand have the slots created/named and use the auto-connection and then also put in your own explicit
connect()
statements. That will lead to duplicate connections. Most of us long-termers use *jusT8 explicitconnect()
s, like the one you show.BTW, have a look at the thread from one of our experts going on in https://forum.qt.io/topic/156017/slot-naming-convention. Note that whichever naming convention people are picking there it is not the special
on_....
for the automatic connect slots. -
@MortyMars simple: don't use underscore in your function name, and you're 100% fine
-
@MortyMars
That's why I tried to explain earlier:we just don't name slots that
on_...
way, which Designer does, so it doesn't arisewhichever naming convention people are picking there it is not the special
on_....
for the automatic connect slots:)
-
It is not my habit to participate in opinions discussion,
maily because it gets (often) sidetracked into criticism of expressions instead of staying on the subject.With that - Qt Inc. published numerous examples.
One of the "features of C++ , when originally introduced was " code reuse ...".
So - why reinvent the wheel when there is a suitable Qt example to "cut and paste" ?Doing that - one gets "stuck "
with using "go to slot" or "old way " to "connect" ...The bottom line - it is (personal) choice what to use,
BUT,
I just do not get the opinions that "it is unreliable , hence it should not be used "
END OF RANT -
@AnneRanch said in "go to slot" vs coded signal/slot connection:
One of the "features of C++, when originally introduced was " reuse ...".
So - why reinvent thre wheel when there is a sitablke Qt example?
The one gets "stuck "
with usign "go to slot" or "old way " to "connect" ...You got yourself into this situation. Nobody forced you to use this whole "QtDesigner"-"GoToSlot"-thing. Because I doubt that anybody uses all these QtDesigner functions and utilities in a serious matter.
These are "difficulties" you wouldn't have, when having proper C++ knowledge.It may seem easy and tempting to put together a GUI in QtDesigner "quick and dirty"... but especially if you want to be able to scrutinize everything and dig down to the roots, as you do (valid, not blaming you on that)... just knowing (or forcing to use) the "GoToSlot" function is.... surprise... not enough.
Qt is a C++ framework after all. And that's not something you can use and control by clicking with your mouse on pretty, shiny WYSIWYG editor windows.
(QtDesigner is actually more WYSIWYG-"lite") -
@Pl45m4 I am tempted to report your post to somebody who cares.
THIS CONSTANT BASHING GOT TO STOP.It is against my nature to discuss such behaviour,
however, I am going to reply in same style.( I do not care TO GET BANNED FROM ThIS CESS POOl
I haVE HAD IT )Would you PLEASE go back to kindergarten school and learn how NOT TO PUT PEOPLE DOWN ?