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. Suppress a single Signal

Suppress a single Signal

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 14.6k 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.
  • HunterMetcalfeH Offline
    HunterMetcalfeH Offline
    HunterMetcalfe
    wrote on last edited by VRonin
    #1

    Hi Everyone!

    Does anyone know how to suppress a single signal from a class. For example say Class A has the signal DataChanged(int). What if sometimes you don't want to receive that signal at ClassB. So far I've been doing the standard:

    disconnect(ObjectA, 
    SIGNAL(DataChanged(int)),
    this,
     SLOT(someSlot()));
    
    /* do some work */
    
    connect(ObjectA, 
    SIGNAL(DataChanged(int)),
    this, 
    SLOT(someSlot()));
    

    I'm just curious if there is a way to say "suppress DataChanged(int)."

    1 Reply Last reply
    0
    • marievinM Offline
      marievinM Offline
      marievin
      wrote on last edited by
      #2

      Hi,

      Maybe you could use the blockSignals method to temporary deactivate the signals of your class. Please note that this method deactivate all the signals of a class and not a specific one.

      bool oldState = ObjectA->blockSignals(true);
      // do some stuff 
      ObjectA->blockSignals(oldState);
      

      Regards,
      Vincent

      1 Reply Last reply
      2
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        To add to @marievin take a look at QSignalBlocker

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        1
        • HunterMetcalfeH Offline
          HunterMetcalfeH Offline
          HunterMetcalfe
          wrote on last edited by
          #4

          @VRonin QSignalBlocker is something similar to what I'm looking for; however, blocksSignals is something that I'm not looking to do as there are a few signals certain classes still need to emit. QSignalBlocker is not available in our version of QT. We are using a version less than Qt 5.3. I wish there was a "suppress" keyword of some sort. I think we will be stuck to the situation I demonstrated above.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            QSignalBlocker is easily re-implemented but from your description it looks rather the other way around. The slot you connected to that signal should not execute. If so, shouldn't you have a boolean enabler that you check at the start of your slot ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            HunterMetcalfeH 1 Reply Last reply
            1
            • SGaistS SGaist

              Hi,

              QSignalBlocker is easily re-implemented but from your description it looks rather the other way around. The slot you connected to that signal should not execute. If so, shouldn't you have a boolean enabler that you check at the start of your slot ?

              HunterMetcalfeH Offline
              HunterMetcalfeH Offline
              HunterMetcalfe
              wrote on last edited by
              #6

              @SGaist As I mentioned above, unfortunately, we do not have access to QSignalBlocker as it is not in our version of QT. When I do the disconnect and then reconnect, the time in between the slot is not executing like I intend. However, what I am asking is if there is a way other than QSignalBlocker and disconnect/reconnect to block a specific signal from an object. For example, the code might look something like suppress dataChanged();

              1 Reply Last reply
              0
              • VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by
                #7

                QObject::blockSignals should be available to you in whatever version of Qt but this blocks all signals emitted from the object.

                Are you sure you are not just looking for an easy fix to a design flaw?

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                HunterMetcalfeH 1 Reply Last reply
                0
                • VRoninV VRonin

                  QObject::blockSignals should be available to you in whatever version of Qt but this blocks all signals emitted from the object.

                  Are you sure you are not just looking for an easy fix to a design flaw?

                  HunterMetcalfeH Offline
                  HunterMetcalfeH Offline
                  HunterMetcalfe
                  wrote on last edited by
                  #8

                  @VRonin I'm not entirely sure how to respond to the - "Are you sure you are not just looking for an easy fix to a design flaw?" However, I will say that this is a massive project with thousands of signals being sent and received by hundreds of different objects all deriving data from data model singletons. So let's look at your solution "QObject::blockSignals" as I'll repeat numerous times, there are certain signals that need to continue being sent and perhaps one or two that need to be muted by a specific listener class. Your solution would prevent any display widget, or perhaps other models, from receiving data updates from the model because you are blocking ALL signals. My question was quite straight forward, I thought, when asking if there was another approach in suppressing a single signal from a class when other signals are needed as they are feeding data to other systems, but perhaps I was wrong. Gathering from your responses, there is no set way to do this other than disconnecting the slot, doing the work, and then reconnecting that slot. I appreciate the input.

                  1 Reply Last reply
                  0
                  • VRoninV Offline
                    VRoninV Offline
                    VRonin
                    wrote on last edited by
                    #9

                    Sorry, I realise I was not clear enough.

                    there are certain signals that need to continue being sent and perhaps one or two that need to be muted by a specific listener class.

                    No, only disconnect would do this

                    Are you sure you are not just looking for an easy fix to a design flaw?

                    What I meant is: are you sure you want to block the signal rather than having a flag in the slot?

                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                    ~Napoleon Bonaparte

                    On a crusade to banish setIndexWidget() from the holy land of Qt

                    1 Reply Last reply
                    1

                    • Login

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