Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Advance Signals and Slots
Arukas last edited by
If I have several widgets connected to a slot. I'd like the slot to know what widget triggered it by passing something like an integer. I looked in the help files and there was a mention of a signal mapper? Is that the best way and/or only way?
joonhwan last edited by
QSignalMapper itself is quite good to use in your considering design, though using QObject::sender() function to know the source of signal in your slot is quite handy.
andre last edited by
Yes, [[doc:QSignalMapper]] has been designed for this scenario. I prefer it over using QObject::sender(), because it makes it a bit clearer what happens IMHO. The method you create to actually do the work, will have the parameter identifying the widget already. Even if you call it directly, or through some other signal/slot connection, it will still work. The sender() approach does not have these saveguards, and you cannot judge from the function signature what will happen exactly. At the very least, you will need to check that sender() returns something sensible before trying to dereference it in your slot.
Thanatos.jsse last edited by
It's exactly what I've looking for.