PDA

View Full Version : in SLOT: determine which signal sent the signal?



vonCZ
8th November 2007, 16:53
hello-

I have a slot with the following code:



QSlider *locSlider = qobject_cast<QSlider *>(sender());
QButtonGroup *locBG = qobject_cast<QButtonGroup *>(sender());

if( QButtonGroup *locBG = qobject_cast<QButtonGroup *>(sender()) )
{ etc... }

if(locSlider == zXag[2])
{ etc.... }

if( (locSlider == NULL) && (locBG == NULL) )
{ etc... }


and 3 things connected to the slot: a QSlider, a QButtonGroup, and a custom signal, customSG. This works: if customSG makes the call, the appropriate conditional is entered (i.e. when locSlider and locBG are NULL). But... what if I want to connect two Signals? How can I determine which Signal made the call? Or in such situations, should I just code a 2nd SLOT?

jacek
8th November 2007, 17:11
It looks like you need more than one slot.

Slots should be implemented in such way that they don't need to know what signal was sent and who sent it. Otherwise you get tight coupling. "Do X or Y, depending on what happened" isn't a good way to code a slot. You should create two separate slots: "do X" and "do Y". This way you can decide what actions should be taken simply by establishing connections.