View Full Version : Finding which widget has triggered a slot
ouekah
26th April 2010, 11:05
Hi,
if I connect two QAbstractButton::clicked(bool) signals to a slot buttonsClicked(bool), is there a way to determine which button was clicked ?
Lesiok
26th April 2010, 11:27
QObject::sender() (http://doc.trolltech.com/4.6/qobject.html#sender)
aamer4yu
26th April 2010, 11:31
and then you will need to cast it to the type you want..
like in the slot :
QPushButton *pSender = qobject_cast<QPushButton *>(sender());
Lykurg
26th April 2010, 13:06
See also QSignalMapper!
squidge
26th April 2010, 13:40
With QSignalMapper being much more OO than ugly type casting of sender()
The result can also be used in switch/case statements, as the return value is constant, so can make for more readable, more optimisable code.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.