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. Signals and Slots, processing order
QtWS25 Last Chance

Signals and Slots, processing order

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 5 Posters 504 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.
  • S Offline
    S Offline
    SPlatten
    wrote on 29 Oct 2023, 08:05 last edited by SPlatten
    #1

    Is there a way to ensure that a slot is processed last if they're are other slots connected to the same signal ?

    I have a signal and slot connection and it seems that the processing order of the signals and slots is not in the order they were connected.

    I need to ensure that one particular slot is always the last to be called.

    Kind Regards,
    Sy

    C J 2 Replies Last reply 29 Oct 2023, 08:06
    0
    • S SPlatten
      29 Oct 2023, 08:05

      Is there a way to ensure that a slot is processed last if they're are other slots connected to the same signal ?

      I have a signal and slot connection and it seems that the processing order of the signals and slots is not in the order they were connected.

      I need to ensure that one particular slot is always the last to be called.

      C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 29 Oct 2023, 08:06 last edited by
      #2

      @SPlatten said in Signals and Slots, processing order:

      Is there a way to ensure that a slot is processed last if they're are other slots connected to the same signal ?

      No

      I need to ensure that one particular slot is always the last to be called.

      Then your design is flawed.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      S 1 Reply Last reply 29 Oct 2023, 08:09
      1
      • C Christian Ehrlicher
        29 Oct 2023, 08:06

        @SPlatten said in Signals and Slots, processing order:

        Is there a way to ensure that a slot is processed last if they're are other slots connected to the same signal ?

        No

        I need to ensure that one particular slot is always the last to be called.

        Then your design is flawed.

        S Offline
        S Offline
        SPlatten
        wrote on 29 Oct 2023, 08:09 last edited by
        #3

        @Christian-Ehrlicher , why do you say that? I want / need an action to be performed last, how can you say the design is flawed when you know little except what I have said ?

        Kind Regards,
        Sy

        1 Reply Last reply
        0
        • S SPlatten
          29 Oct 2023, 08:05

          Is there a way to ensure that a slot is processed last if they're are other slots connected to the same signal ?

          I have a signal and slot connection and it seems that the processing order of the signals and slots is not in the order they were connected.

          I need to ensure that one particular slot is always the last to be called.

          J Offline
          J Offline
          JonB
          wrote on 29 Oct 2023, 11:49 last edited by JonB
          #4

          @SPlatten

          Is there a way to ensure that a slot is processed last if they're are other slots connected to the same signal ?

          It should be last one connected.

          I have a signal and slot connection and it seems that the processing order of the signals and slots is not in the order they were connected.

          I believe it is done in the order of connection. Minimal example?

          I need to ensure that one particular slot is always the last to be called.

          • Connect it last per above.
          • If you don't trust that, or it doesn't work like that, or it's too hard to connect in particular order, just write your own "dispatcher", i.e. connect signal to your dispatcher as lone slot, "connect" (your connect, not Qt's) original slots to your dispatcher only, implement desired "queue" (e.g. such-and-such a slot to be called last) in your dispatcher so that is the order you call things from your "connections" to this dispatcher.
          C K 2 Replies Last reply 29 Oct 2023, 12:44
          0
          • J JonB
            29 Oct 2023, 11:49

            @SPlatten

            Is there a way to ensure that a slot is processed last if they're are other slots connected to the same signal ?

            It should be last one connected.

            I have a signal and slot connection and it seems that the processing order of the signals and slots is not in the order they were connected.

            I believe it is done in the order of connection. Minimal example?

            I need to ensure that one particular slot is always the last to be called.

            • Connect it last per above.
            • If you don't trust that, or it doesn't work like that, or it's too hard to connect in particular order, just write your own "dispatcher", i.e. connect signal to your dispatcher as lone slot, "connect" (your connect, not Qt's) original slots to your dispatcher only, implement desired "queue" (e.g. such-and-such a slot to be called last) in your dispatcher so that is the order you call things from your "connections" to this dispatcher.
            C Offline
            C Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 29 Oct 2023, 12:44 last edited by
            #5

            @JonB said in Signals and Slots, processing order:

            I believe it is done in the order of connection.

            It is, and also documented nowaydays that it is so iirc.
            But this does not solve the design flaw :)

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            S 1 Reply Last reply 30 Oct 2023, 08:16
            0
            • J JonB
              29 Oct 2023, 11:49

              @SPlatten

              Is there a way to ensure that a slot is processed last if they're are other slots connected to the same signal ?

              It should be last one connected.

              I have a signal and slot connection and it seems that the processing order of the signals and slots is not in the order they were connected.

              I believe it is done in the order of connection. Minimal example?

              I need to ensure that one particular slot is always the last to be called.

              • Connect it last per above.
              • If you don't trust that, or it doesn't work like that, or it's too hard to connect in particular order, just write your own "dispatcher", i.e. connect signal to your dispatcher as lone slot, "connect" (your connect, not Qt's) original slots to your dispatcher only, implement desired "queue" (e.g. such-and-such a slot to be called last) in your dispatcher so that is the order you call things from your "connections" to this dispatcher.
              K Offline
              K Offline
              kshegunov
              Moderators
              wrote on 29 Oct 2023, 20:30 last edited by
              #6

              @JonB said in Signals and Slots, processing order:

              I believe it is done in the order of connection. Minimal example?

              Across thread boundaries enqueueing the event is done in a non-deterministic way (which is also the only way). This is also why it's absurd to require a specific order of slot call invocations, which is what @Christian-Ehrlicher alluded to.

              What one can (reliably) do is to model a state machine, and push the state as calls come. Thus, allowing you to know what are the possible transitions. Incidentally, this is what people have been doing for ages for anything async, where call order is not strictly defined (which is most things - GUI, network, etc).

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply
              4
              • C Christian Ehrlicher
                29 Oct 2023, 12:44

                @JonB said in Signals and Slots, processing order:

                I believe it is done in the order of connection.

                It is, and also documented nowaydays that it is so iirc.
                But this does not solve the design flaw :)

                S Offline
                S Offline
                SimonSchroeder
                wrote on 30 Oct 2023, 08:16 last edited by
                #7

                @Christian-Ehrlicher said in Signals and Slots, processing order:

                I believe it is done in the order of connection.

                It is, and also documented nowaydays that it is so iirc.

                Have you any pointers where it is documented? I've had situations, at least with Qt 5, where it was not in order. It might have been from one thread to one other, but definitely not multiple threads. If there is an order, I would at least also expect that even across thread borders within one thread they are ordered (as the signaling thread cannot overtake itself).

                C 1 Reply Last reply 30 Oct 2023, 08:39
                0
                • S SimonSchroeder
                  30 Oct 2023, 08:16

                  @Christian-Ehrlicher said in Signals and Slots, processing order:

                  I believe it is done in the order of connection.

                  It is, and also documented nowaydays that it is so iirc.

                  Have you any pointers where it is documented? I've had situations, at least with Qt 5, where it was not in order. It might have been from one thread to one other, but definitely not multiple threads. If there is an order, I would at least also expect that even across thread borders within one thread they are ordered (as the signaling thread cannot overtake itself).

                  C Offline
                  C Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 30 Oct 2023, 08:39 last edited by
                  #8

                  @SimonSchroeder It was not documented in Qt5, then a discussion on the ml and then this was added: https://doc.qt.io/qt-6/signalsandslots.html#signals (but it seems to be backported to Qt5).
                  But I must admit it's a little bit to generic as it does not cover the queued-connection case where it's not defined. Even though it's on-order when passing all from one to another thread since the events are added to the receivers event queue.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  3

                  7/8

                  30 Oct 2023, 08:16

                  • Login

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