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. Clear pending signal
QtWS25 Last Chance

Clear pending signal

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 5 Posters 4.4k 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.
  • M Offline
    M Offline
    MartinD
    wrote on 23 Mar 2017, 13:39 last edited by
    #1

    Hi,
    I have a QObject which emits signal which is directly (only one thread in application) connected to many receiver QObjects' slots. I emit signal and then slots are called one by one by Qt. In some slot I want to tell that subsequent slots should not be called (because the signal was served in that particular QObject).

    Is that possible?

    J 2 Replies Last reply 23 Mar 2017, 14:15
    0
    • M Offline
      M Offline
      mostefa
      wrote on 23 Mar 2017, 14:09 last edited by mostefa
      #2

      Hi @MartinD

      What about disconnect your signal?

      Like connect static function you have actually a static disconnect function

      http://doc.qt.io/qt-5/qobject.html#disconnect

      Hope this can help !

      void YourClass::onSomeSlot
      {
      //Do somethings
      .
      .
      .
      //DISCONNECT SIGNAL
      disconnect(yourObject,SIGNAL(triggered()),this,SLOT(yourSlot()));
      
      }
      
      1 Reply Last reply
      2
      • M MartinD
        23 Mar 2017, 13:39

        Hi,
        I have a QObject which emits signal which is directly (only one thread in application) connected to many receiver QObjects' slots. I emit signal and then slots are called one by one by Qt. In some slot I want to tell that subsequent slots should not be called (because the signal was served in that particular QObject).

        Is that possible?

        J Offline
        J Offline
        J.Hilk
        Moderators
        wrote on 23 Mar 2017, 14:15 last edited by J.Hilk
        #3

        @MartinD

        To add to @mostefa

        adding the parameter Qt::ConnectionType ,with Qt::UniqueConnection might also help in your situation


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        2
        • F Offline
          F Offline
          Flotisable
          wrote on 23 Mar 2017, 14:55 last edited by
          #4

          Is it better to use the event system in this case?

          I think the signals&slots mechanism is not designed to be used this way. Signals and slots should not know anything about outside world, this way objects will not be tied together.

          maybe insert an intermediate object between the object that emit the signal and objects that have slot connected to the signal to deal with it, or using event system and filter the event a good choice?

          1 Reply Last reply
          3
          • M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 23 Mar 2017, 15:43 last edited by
            #5

            Hi
            I agree with @Flotisable that signals are not designed for such dispatcher design.
            You could have a man in the middle class that gets the signal and then
            call one or more connected objects but a raw design with connect only will be clumsy.
            Your thread could do it
            but Im wondering why you connect many up , if only one should handle the signal?

            1 Reply Last reply
            1
            • M MartinD
              23 Mar 2017, 13:39

              Hi,
              I have a QObject which emits signal which is directly (only one thread in application) connected to many receiver QObjects' slots. I emit signal and then slots are called one by one by Qt. In some slot I want to tell that subsequent slots should not be called (because the signal was served in that particular QObject).

              Is that possible?

              J Offline
              J Offline
              J.Hilk
              Moderators
              wrote on 23 Mar 2017, 15:50 last edited by
              #6

              @MartinD

              to add to @mrjj and @Flotisable , because the idea of using a 'signal helper' is the correct one.

              If, you connect multiple slots to a single Signal it is not guaranteed that slots are always called in the exact same order.

              Even so it seems most of the time, that the "First connect-statement" is also executed first when the signal comes. This is not the regular case, the execute order depends on many different things, with compile order being a minor one.


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply
              1
              • M Offline
                M Offline
                MartinD
                wrote on 23 Mar 2017, 16:39 last edited by
                #7

                Thanks everybody. I will leave my idea and rather use Qt event system.

                M 1 Reply Last reply 23 Mar 2017, 16:51
                0
                • M MartinD
                  23 Mar 2017, 16:39

                  Thanks everybody. I will leave my idea and rather use Qt event system.

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 23 Mar 2017, 16:51 last edited by
                  #8

                  @MartinD
                  well you can also just drop the connects and call manually
                  MetaObject::invokeMethod( textEdit, "append", Qt::QueuedConnection, Q_ARG( QString, myString ) );
                  if u already have the slots etc.

                  1 Reply Last reply
                  1

                  5/8

                  23 Mar 2017, 15:43

                  • Login

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