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. Signal inside readyread of QUdpsocket

Signal inside readyread of QUdpsocket

Scheduled Pinned Locked Moved Unsolved General and Desktop
signal & slotthreadingudpqudpsocket
7 Posts 3 Posters 1.1k 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.
  • L Offline
    L Offline
    Lior
    wrote on 4 Jun 2020, 20:40 last edited by
    #1

    Hi, i have a question that i cant verify.

    1. Is emting in readyread is thread safe?
    2. Assuming the data is recived periodcly and fast, is it posiable that the signal is emting again? (before the last emit is finished).
    1 Reply Last reply
    0
    • C Online
      C Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 5 Jun 2020, 04:20 last edited by
      #2

      @Lior said in Signal inside readyread of QUdpsocket:

      Is emting in readyread is thread safe?

      Yes

      Assuming the data is recived periodcly and fast, is it posiable that the signal is emting again? (before the last emit is finished).

      When there are threads involved, yes. For QUdpSocket I don't see why you need a thread.

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

      L 1 Reply Last reply 5 Jun 2020, 04:48
      3
      • C Christian Ehrlicher
        5 Jun 2020, 04:20

        @Lior said in Signal inside readyread of QUdpsocket:

        Is emting in readyread is thread safe?

        Yes

        Assuming the data is recived periodcly and fast, is it posiable that the signal is emting again? (before the last emit is finished).

        When there are threads involved, yes. For QUdpSocket I don't see why you need a thread.

        L Offline
        L Offline
        Lior
        wrote on 5 Jun 2020, 04:48 last edited by
        #3

        @Christian-Ehrlicher, I neex different thread becuase i have "work" on the data that i reciving . And becuase it peridic, i dont want to open the socket on the ui main thread.

        1 Reply Last reply
        0
        • C Online
          C Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 5 Jun 2020, 15:49 last edited by
          #4

          So when the socket lives in the thread where the slot is, then no signal will be emitted before the first one is 'done' except you use Qt::QueuedConnection.

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

          L 1 Reply Last reply 6 Jun 2020, 20:04
          0
          • V Offline
            V Offline
            VRonin
            wrote on 5 Jun 2020, 16:23 last edited by
            #5

            just to be clear, if the signal emitter and the slot receiver are in 2 different threads, connecting to readyRead is thread safe but accessing the socket directly isn't (i.e. calling socket->read()/socket->readAll() in the connected slot is a race condition)

            "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
            3
            • C Christian Ehrlicher
              5 Jun 2020, 15:49

              So when the socket lives in the thread where the slot is, then no signal will be emitted before the first one is 'done' except you use Qt::QueuedConnection.

              L Offline
              L Offline
              Lior
              wrote on 6 Jun 2020, 20:04 last edited by
              #6

              tank you @Christian-Ehrlicher and @VRonin

              I tried to write small example.
              In pseodo
              class Worker
              - hold QUdpSocket socket;
              - connect readyread() to processReciveData.

              • processReciveData read the data and emit OnNewData to mainUi tread
              • worker hold by mainUI thread.

              mainwindow

              • hold worker
              • connect workerThread, OnNewData, this, processNewData

              I created anthor app that send data to the socket.
              - use timer with timeOut

              1. when i send the data one by one on timeOut , every thing is ok.

              2. when i send in for loop (let say 4 times) , on time out. the ui skip data , i verify it by counter.
                i recived all the 4 but see on canvas only the last one. i understend that it because the send is very fast. so i tried to slow down the worker thread and take me to the qustion .

              3. the qustion - when i tried to slow down the worker with msleep of 100 (100 msec) , only for testing. the UI start to lag and not responeding, untill i stoped the udp sender.

              why the UI main thread stoped to respond ? the msleep is in anthor thread.

              i can add some code if needed.

              1 Reply Last reply
              0
              • C Online
                C Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 7 Jun 2020, 13:11 last edited by
                #7

                @Lior said in Signal inside readyread of QUdpsocket:

                why the UI main thread stoped to respond ? the msleep is in anthor thread.

                Because you do it wrong (and I would guess the msleep is not in the thread but in the gui thread) but without code...

                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
                1

                7/7

                7 Jun 2020, 13:11

                • Login

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