Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Disconnect specific slot from all signals

Disconnect specific slot from all signals

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 52.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    goocreations
    wrote on 17 Aug 2012, 15:23 last edited by
    #1

    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?

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vezprog
      wrote on 17 Aug 2012, 19:39 last edited by
      #2

      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.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DerManu
        wrote on 17 Aug 2012, 19:43 last edited by
        #3

        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.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goocreations
          wrote on 17 Aug 2012, 20:23 last edited by
          #4

          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.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DKvita
            wrote on 18 Aug 2012, 19:41 last edited by
            #5

            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()));@

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goocreations
              wrote on 18 Aug 2012, 19:46 last edited by
              #6

              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”?

              1 Reply Last reply
              0

              5/6

              18 Aug 2012, 19:41

              • Login

              • Login or register to search.
              5 out of 6
              • First post
                5/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved