Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Order of execution if a slot is called twice by the same signal
Forum Updated to NodeBB v4.3 + New Features

Order of execution if a slot is called twice by the same signal

Scheduled Pinned Locked Moved Unsolved C++ Gurus
5 Posts 3 Posters 596 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.
  • R Offline
    R Offline
    RLocksley
    wrote on last edited by RLocksley
    #1

    I have the following situation:

    My onReadyRead() slot is reading from a TCP socket, collects the payload of TCP-packets until one packet on layer 5, which can be bigger than one TCP packet, is full and then emits a signal decryptPacket(QByteArray& packet).
    The onDecryptPacket(QByteArray& packet) slot decrypts the packet and then emits another signal processPacket(QByteArray& decryptedPacket).
    The packets can be very different in size, so the runtime of onDecryptPacket() can be very different.
    Because the size of the packets can be large I have to call processEvent() inside onDecryptPacket() and onProcessPacket().

    My question:
    Let us assume packet A is very large and packet B very small.
    Packet A arrives first and Packet B second.
    Is it possible that if onDecryptPacket(packetA) takes so long, that in the mean time onReadyRead() emits decryptPacket(packetB) and onDecryptPacket(packetB) emits processPacket(decryptedPacketB) before onDecryptPacket(packetA) emits processPacket(decryptedPacketA)?
    It seems to be possible because of the processEvent() calls.

    Does a standard way exist, which avoids a freezing UI and ensures that processPacket(decryptedPacketA) is emitted before processPacket(decryptedPacketB)?

    jsulmJ J.HilkJ 2 Replies Last reply
    0
    • R RLocksley

      I have the following situation:

      My onReadyRead() slot is reading from a TCP socket, collects the payload of TCP-packets until one packet on layer 5, which can be bigger than one TCP packet, is full and then emits a signal decryptPacket(QByteArray& packet).
      The onDecryptPacket(QByteArray& packet) slot decrypts the packet and then emits another signal processPacket(QByteArray& decryptedPacket).
      The packets can be very different in size, so the runtime of onDecryptPacket() can be very different.
      Because the size of the packets can be large I have to call processEvent() inside onDecryptPacket() and onProcessPacket().

      My question:
      Let us assume packet A is very large and packet B very small.
      Packet A arrives first and Packet B second.
      Is it possible that if onDecryptPacket(packetA) takes so long, that in the mean time onReadyRead() emits decryptPacket(packetB) and onDecryptPacket(packetB) emits processPacket(decryptedPacketB) before onDecryptPacket(packetA) emits processPacket(decryptedPacketA)?
      It seems to be possible because of the processEvent() calls.

      Does a standard way exist, which avoids a freezing UI and ensures that processPacket(decryptedPacketA) is emitted before processPacket(decryptedPacketB)?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @RLocksley said in Order of execution if a slot is called twice by the same signal:

      Is it possible that if onDecryptPacket(packetA) takes so long, that in the mean time onReadyRead() emits decryptPacket(packetB)

      Not if you do not allow the event loop to run (which is normal case when you're executing a slot or something else).
      So, in normal case your slots will be executed one after another.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      4
      • R RLocksley

        I have the following situation:

        My onReadyRead() slot is reading from a TCP socket, collects the payload of TCP-packets until one packet on layer 5, which can be bigger than one TCP packet, is full and then emits a signal decryptPacket(QByteArray& packet).
        The onDecryptPacket(QByteArray& packet) slot decrypts the packet and then emits another signal processPacket(QByteArray& decryptedPacket).
        The packets can be very different in size, so the runtime of onDecryptPacket() can be very different.
        Because the size of the packets can be large I have to call processEvent() inside onDecryptPacket() and onProcessPacket().

        My question:
        Let us assume packet A is very large and packet B very small.
        Packet A arrives first and Packet B second.
        Is it possible that if onDecryptPacket(packetA) takes so long, that in the mean time onReadyRead() emits decryptPacket(packetB) and onDecryptPacket(packetB) emits processPacket(decryptedPacketB) before onDecryptPacket(packetA) emits processPacket(decryptedPacketA)?
        It seems to be possible because of the processEvent() calls.

        Does a standard way exist, which avoids a freezing UI and ensures that processPacket(decryptedPacketA) is emitted before processPacket(decryptedPacketB)?

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        @RLocksley

        takes so long

        did you sprinkle your code with processEvent() calls so the ui doesn't freeze in your long decrypt phases ?
        Because that will case readyRead to be emitted a second time before your slot is finished


        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.

        R 1 Reply Last reply
        4
        • J.HilkJ J.Hilk

          @RLocksley

          takes so long

          did you sprinkle your code with processEvent() calls so the ui doesn't freeze in your long decrypt phases ?
          Because that will case readyRead to be emitted a second time before your slot is finished

          R Offline
          R Offline
          RLocksley
          wrote on last edited by
          #4

          @J-Hilk @jsulm Thank you for the answers. I edited my question.

          J.HilkJ 1 Reply Last reply
          0
          • R RLocksley

            @J-Hilk @jsulm Thank you for the answers. I edited my question.

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @RLocksley alight,

            first of, good that you didn't jump into "threading" right away, its a complicated topic and easy to get wrong.

            But the use of processEvents() is not good either :D

            in your case you should do your onDecryptPacket function in parallel.

            Qt offers a range of way on how to do that, see

            https://doc.qt.io/qt-5/qthread.html
            https://doc.qt.io/qt-5/qtconcurrent-index.html

            and I'll link you to my GitHub page, where I have an example use case of all common Qt ways
            https://github.com/DeiVadder/QtThreadExample

            since you do most function calls already via Signals, it should be easy to move to a Qt threading method


            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
            5

            • Login

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