[Qt-interest] How to find out which SIGNAL was sent
Rainer Wiesenfarth
Rainer.Wiesenfarth at inpho.de
Thu Nov 18 09:56:41 CET 2010
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> how can I find out which signal was sent from a specific
> widget/QObject?
>
> For example:
> connect (myWidget1, SIGNAL(sig1()), this, SLOT(doSomething()));
> connect (myWidget1, SIGNAL(sig2()), this, SLOT(doSomething()));
> connect (myWidget2, SIGNAL(sig1()), this, SLOT(doSomething()));
> connect (myWidget2, SIGNAL(sig2()), this, SLOT(doSomething()));
>
> void MyClass::doSomething() {
> qDebug() << sender(); // myWidget1, MyWidget2
> }
>
> To find out the widget is simple, just call sender(), but how can I get
> the signal which was sent (in this example sig1() or sig2())?
Short answer: Don't!
Longer answer: One of the basics behind the signal/slot stuff is to enable
notifications between two objects that need (and should) not know each
other. If your receiver has to act different depending on the sender (and
signal) this may indicate a bad design.
Best Regards / Mit freundlichen Grüßen
Rainer Wiesenfarth
--
INPHO GmbH * Smaragdweg 1 * 70174 Stuttgart * Germany
phone: +49 711 2288 10 * fax: +49 711 2288 111 * web: www.inpho.de
place of business: Stuttgart * managing director: Johannes Saile
commercial register: Stuttgart, HRB 9586
Leader in Photogrammetry and Digital Surface Modelling
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 6426 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101118/83095735/attachment.bin
More information about the Qt-interest-old
mailing list