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
Forum Updated to NodeBB v4.3 + New Features

Disconnect specific slot from all signals

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 53.0k Views 1 Watching
  • 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 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 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 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 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 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 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

              • Login

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