Results 1 to 2 of 2

Thread: Disconnect all SLOTS in QObject connected from all other SIGNALS

  1. #1
    Join Date
    Aug 2015
    Posts
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Disconnect all SLOTS in QObject connected from all other SIGNALS

    I've been struggling with this. I've not found a way to accomplish the following ...

    I have a number of different signals connected to various slots in a single QObject. Is there any disconnect function that can be used to disconnect all signals connected to a all slots in a QObject?

    For example, let's say I have a QObject (we'll call MyQObject for now) that I would simply like to take temporarily offline. I'd like all signals that are connected to the slots of the MyQObject to be essentially disconnected (but only temporarily). Then, when I am ready for MyQObject to go back online, for the signals that were once connected to the slots of MyQObject to be re-established.

    For example: (assume MyQObject's variable is called myQObject)

    QObject::connect(senderObject1, SIGNAL(doSomethingA()), myQObject, SLOT(slotDoA()));
    QObject::connect(senderObject2, SIGNAL(doSomethingB()), myQObject, SLOT(slotDoB()));
    QObject::connect(senderObject3, SIGNAL(doSomethingC()), myQObject, SLOT(slotDoC()));

    Therefore, I'd like to temporarily disconnect all signals that are being emitted to myQObject's slots. MyQObject would then remain offline for a period of time (for whatever reason that may be). Then, to have the signals that ONCE were connected to MyQObject automagically re-connected simply by a single call.

    Again, I want to disconnect ALL signals, without knowing the objects that are connected to the slot. Then, to call something that will automagically reconnect the signals back to the MyQObject slots that the other objects were once connected.

    Any ideas? Thoughts on how to do this? Maybe something in QMetaObject i'm unaware of to do this?

    One thought, was perhaps to suspend the QObject as if the QObject had no thread it belonged to and so wouldn't have the slots fire. But, I've not found a way to do this.

    Thoughts? Ideas? Suggestions?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Disconnect all SLOTS in QObject connected from all other SIGNALS

    I don't think there is any information inside the receiver object which signals are connected to it.

    One thing you could do is not connect to the receiver directly but to a proxy, an object that has the same slots as the actual receiver and also signals with matching arguments.
    The proxy's slots would just emit the signal again when its slots are activated.
    The actual receiver would be connected to the proxy's signals.

    Then you can simply block the forwarding by calling blockSignals() on the proxy.

    Cheers,
    _

Similar Threads

  1. Questions about signals/slots and QObject lifetimes
    By themolecule in forum Qt Programming
    Replies: 11
    Last Post: 24th May 2014, 18:45
  2. Replies: 2
    Last Post: 18th April 2013, 12:15
  3. Replies: 1
    Last Post: 7th February 2011, 15:44
  4. Signals and Slots - Moc QObject Problem
    By GBayo1 in forum Qt Programming
    Replies: 6
    Last Post: 22nd March 2010, 16:35
  5. Disconnect slot when another is being connected
    By holst in forum Qt Programming
    Replies: 4
    Last Post: 8th September 2009, 09:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.