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. Do queued signal-slot connections and custom events arrive in order?
QtWS25 Last Chance

Do queued signal-slot connections and custom events arrive in order?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 589 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.
  • A Offline
    A Offline
    aart
    wrote on last edited by
    #1

    I have a GUI thread and a worker thread in my application and would like to communicate to the worker thread with both signal-slot connections and by supplying the worker thread with custom events.
    If I emit a signal (A), then post a custom event (B), emit signal (A) again and post event (B) again, is it guaranteed that the order of execution in the worker thread is A -> B -> A -> B, or could it be possible that first all the signal-slots are handled and then all the events such that A -> A -> B -> B.
    I need to take this into account into the design of the application, and did not find any documentation on this.
    Thanks in advance!

    kshegunovK 1 Reply Last reply
    0
    • A aart

      I have a GUI thread and a worker thread in my application and would like to communicate to the worker thread with both signal-slot connections and by supplying the worker thread with custom events.
      If I emit a signal (A), then post a custom event (B), emit signal (A) again and post event (B) again, is it guaranteed that the order of execution in the worker thread is A -> B -> A -> B, or could it be possible that first all the signal-slots are handled and then all the events such that A -> A -> B -> B.
      I need to take this into account into the design of the application, and did not find any documentation on this.
      Thanks in advance!

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #4

      @aart said in Do queued signal-slot connections and custom events arrive in order?:

      If I emit a signal (A), then post a custom event (B), emit signal (A) again and post event (B) again, is it guaranteed that the order of execution in the worker thread is A -> B -> A -> B, or could it be possible that first all the signal-slots are handled and then all the events such that A -> A -> B -> B.

      It's guaranteed insofar as the current implementation is such that this is true, and importantly this can only be true if and only if you have one single thread that does the emissions and/or posting of events.

      If you have two threads that feed the worker the order is undetermined.
      If the current implementation changes the order is undefinable.

      So to conclude: Do not depend on event/slot execution order!

      Read and abide by the Qt Code of Conduct

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

        Hi,

        I am not aware of such a guarantee between signal generated events and other events.

        Can you explain a bit more your design which requires such a guarantee ?

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

        1 Reply Last reply
        0
        • A Offline
          A Offline
          aart
          wrote on last edited by
          #3

          I guess there is no hard requirement to implement it this way, i could also only use signal slots i guess, I was just curious because i could not find anything about this topic online, and i thought it might make the api a bit cleaner.

          1 Reply Last reply
          0
          • A aart

            I have a GUI thread and a worker thread in my application and would like to communicate to the worker thread with both signal-slot connections and by supplying the worker thread with custom events.
            If I emit a signal (A), then post a custom event (B), emit signal (A) again and post event (B) again, is it guaranteed that the order of execution in the worker thread is A -> B -> A -> B, or could it be possible that first all the signal-slots are handled and then all the events such that A -> A -> B -> B.
            I need to take this into account into the design of the application, and did not find any documentation on this.
            Thanks in advance!

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by
            #4

            @aart said in Do queued signal-slot connections and custom events arrive in order?:

            If I emit a signal (A), then post a custom event (B), emit signal (A) again and post event (B) again, is it guaranteed that the order of execution in the worker thread is A -> B -> A -> B, or could it be possible that first all the signal-slots are handled and then all the events such that A -> A -> B -> B.

            It's guaranteed insofar as the current implementation is such that this is true, and importantly this can only be true if and only if you have one single thread that does the emissions and/or posting of events.

            If you have two threads that feed the worker the order is undetermined.
            If the current implementation changes the order is undefinable.

            So to conclude: Do not depend on event/slot execution order!

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            5
            • Kent-DorfmanK Offline
              Kent-DorfmanK Offline
              Kent-Dorfman
              wrote on last edited by aha_1980
              #5

              @kshegunov said in Do queued signal-slot connections and custom events arrive in order?:

              So to conclude: Do not depend on event/slot execution order!

              What he said. Think of them as asynchronous, even if in the current implementation they are not.

              1 Reply Last reply
              2

              • Login

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