Unsolved Signal inside readyread of QUdpsocket
Hi, i have a question that i cant verify.
- Is emting in readyread is thread safe?
- Assuming the data is recived periodcly and fast, is it posiable that the signal is emting again? (before the last emit is finished).
Is emting in readyread is thread safe?
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.
@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.
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.
VRonin last edited by
just to be clear, if the signal emitter and the slot receiver are in 2 different threads, connecting to
readyReadis thread safe but accessing the socket directly isn't (i.e. calling
socket->readAll()in the connected slot is a race condition)
I tried to write small example.
- hold QUdpSocket socket;
- connect readyread() to processReciveData.
- processReciveData read the data and emit OnNewData to mainUi tread
- worker hold by mainUI thread.
- hold worker
- connect workerThread, OnNewData, this, processNewData
I created anthor app that send data to the socket.
- use timer with timeOut
when i send the data one by one on timeOut , every thing is ok.
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 .
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.