PDA

View Full Version : Disconnect slot when another is being connected



holst
7th September 2009, 15:58
Hi,
I have a QPushButton, in a QDialog, that has its signal "clicked()" connected to one slot that is part of the Dialog.
I want that someone, externally of this Dialog, connects to same signal then disconnects from the other slot.
I want a QPushButton that can has only one slot connected to its signals "clicked()"
I see this function:
QObject::connectNotify(const char * signal)


But notifies when the connection is already made. So if I overload this function to do something like this:


void CMyButton::connectNotify(const char * signal)
{
this->disconnect(SIGNAL(signal));
// How to connect the last signal-slot made?
}


I disconnect all, including the last connection made that I want to keep.

Any ideas??

Thanks

wysota
7th September 2009, 16:14
If you want to have only one listener, it might be easier to not use signals and slots at all - just provide a "setListener()" method where you will pass a pointer to the object you want notified.

holst
8th September 2009, 09:25
Yes, I'm so focused in signals/slots that I forgot the "old-ways".
The only thing is that in all the app we're using the signal/slot mechanism I don't want to be different here.

Thank you.

wysota
8th September 2009, 09:39
But signals and slots is a way of notifing environment of an object about changes in the object. You shouldn't assume that only one person will be listening to that. So you're breaking the signal/slot paradigm anyway.

holst
8th September 2009, 09:49
You're right.
Is too tricky/dirty and at last it will be confusing because I break the signals/slots paradigm.

Thank you :)