Disconnect specific slot from all signals
-
wrote on 17 Aug 2012, 15:23 last edited by
I have a number of different signals connected to one slot. Is there any disconnect function that can be used to disconnect everything connected to a specific slot?
For example:
@QObject::connect(object1, SIGNAL(a()), receiver, SLOT(slot()));
QObject::connect(object2, SIGNAL(b()), receiver, SLOT(slot()));
QObject::connect(object3, SIGNAL(c()), receiver, SLOT(slot()));@Now I want a function to disconnect all the signals from receiver’s slot(). There is an option:
@QObject::disconnect(receiver, SLOT(slot()));@
but this connects only the signals in the current object. I want to disconnect ALL signals, without knowing the objects that are connected to the slot.
Any ideas?
-
wrote on 17 Aug 2012, 19:39 last edited by
If you deleted receiver (the parent class), then all of the signals/slots associated with that object will be deleted as well on cleanup...or delete the children classes...that's the only way I can think of doing it.
-
wrote on 17 Aug 2012, 19:43 last edited by
I've looked for a method that does what you want (including tricks with the Qt Meta-Object system) for quite a while and haven't found one.
-
wrote on 17 Aug 2012, 20:23 last edited by
Ahhh. Something like this is quite common in the system I writing. And dvez43, I can't delete anything since I have to use the objects later on.
-
wrote on 18 Aug 2012, 19:41 last edited by
May this help
@QObject::connect(object1, SIGNAL(a()), receiver, SIGNAL(LocalProxySignal()));
QObject::connect(object2, SIGNAL(b()), receiver, SIGNAL(LocalProxySignal()));
QObject::connect(object3, SIGNAL(c()), receiver, SIGNAL(LocalProxySignal()));QObject::connect(receiver, SIGNAL(LocalProxySignal()), receiver, SLOT(slot()));@
... and disconnect
@QObject::disconnect(receiver, SLOT(slot()));@ -
wrote on 18 Aug 2012, 19:46 last edited by
Interesting. Yes this might work, but it’s a small overhead; so not a very “clean” solution. But thanks, this will do for now. Is there a reason why there isn’t a function like this? Should this maybe be reported as a “new feature”?
5/6