View Full Version : How to find out whom invoked a slot?
vulee
2nd December 2010, 17:31
I have a slot for QSpinBox. This slot could be invoked by either user clicked on the spin box or programmatically changed the spin box value. If I run in debug mode, I could look at the stack trace to detect who invoked the method. Is there is way to find the invoker programmatically?
Thanks
squidge
2nd December 2010, 19:12
There's sender() if thats any use to you? It only reports the object that emitted the signal though...
I would expect however that the two events you state would be two different signals but both going to a single slot, therefore QSignalMapper would be more OO.
vulee
2nd December 2010, 21:42
Thanks squidge.
sender() would work since it returns NULL when the slot was not activated by the signal.
The QSignalMapper is also interesting.
wysota
2nd December 2010, 21:55
sender() should never be used in a method that may be invoked by means other than a signal-slot connection. You can't rely it will always be returning null in case of a direct call. If the call is made from a method invoked as a slot, sender() will probably contain the object that called the original slot.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.