Solved QUdpSocket stop receiving data
-
Is it possible something else is getting the udp data? UDP data is only sent once and can only be received once, but any UDP socket can receive and keep it.
Maybe you have some other app on your system intercepting that data after a while?
-
I suspect the issue with reading. Can you check how you are processing the data ? You may not be reading the data in some condition. unless you read the data readyRead signal will not be emitted.
Can you check if thread is still running ? I know this is remote chance.
-
Hi guys,
Thanks for the input. I think I have solved the issue. The threads are running fine. It turned out that, this problem occurs when I create the UDP socket in the worker thread class without passing its parent.
i.e
Instead of declaring :
@QUdpSocket *socket = new QUdpSocket;@It should be:
@QUdpSocket *socket = new QUdpSocket(this);@After fixing this, I could continuously receive data with a period of 25ms without any disruption.
-
That's kinda weird. I'm glad it's solved for now, but I can't really see any cases where having a parent would matter for receiving data.
Especially since it would receive some but not all the data. Very weird indeed. Glad it's working though.
-
Exactly. I find it very weird though. And I am still not sure how this could solve the problem. But I have tested more than once and it is no longer failing. If I remove the parent, it fails.
-
Just out of curiousity, what type of object is "this"?
-
"this" is just a class I created myself to receive and process the data. After processing, it emit signals by transmitting the data received as a parameter to some other class. I have inherited the class from QObject though and it runs in a worker thread
-
Hmm, so no reason there. Oh well, I'll stop thinking about it now since it's working for you. I just hate not knowing why something works, lol. :)
-
Same here. :)
-
Hi,
Just an educated guess, you wrote that the socket is in a worker thread so I presume that it's a worker object that you used moveToThread on ? If so, the socket was not moved before since it wasn't parented to the worker object and thus was not in the correct thread to work.
-
Yes, I used moveToThread from the main thread. That makes so much sense. Thanks SGaist
-
Hey is it possible to share how you are sending data from matlab to QT .How did you set up both environment? It would be nice if you can share something.
-
@Surizer
Hi and welcome to this forumJust make you aware that the post is rather old. Furthermore from the user's profile you can see that the user might no longer hang out in the forum. His last activity was about 2 years according to his profile.
Possibly you start a new thread with a link to this thread here. May be someone else knows a solution.