QUdpSocket High rate message reading
Hi, everybody!
I have a strange issue in working with QUdpSocket and readyRead signal, I can say it's not working as I think,
I create a QUdpSocket and bind it to some port , connect the readyRead signal to my slot and I read all the pending datagram as below
Code:
if(!udp_listener)
{
connect(udp_listener, SiGNAL(readyRead()), this, SLOT(readBuffers(), Qt::QueuedConnection);
// the rate of receiving data is 10 msec if i dont put Qt::QueuedConnection, it didn't receive any more signal after first received. why ???
// change the rate of data to 1 sec and this code work well without Qt::QueuedConnection !!!
}
udp_lister.bind(Any, 5555);
and my readBuffers code
Code:
void readBuffers() {
while(udp_listener->hasPendingDatagrams()) {
received.resize(udp_listener->pendingDatagramSize());
udp_listener->readDatagram(received, received.size(), 0,0);
buffer.append(received);
// Do some job in 1 msec on buffer and take data from buffer
if(/* some works done */) buffer.clear(); // almost every time my buffer got cleared
}
}
I thought my problems solved with using of Qt::QueuedConnection but today I add another widget to my project and updated it every 100 msec and I don't know how but my slot didn't signaled any more after 2 seconds.
If I change my timer interval or sending data rate to 1 sec, everything is fine.
all of my classes and my widgets live in main program's thread and I don't use another thread, but it seems I should!
so why signals dropped by Qt eventloop.
I check my socket state and it did'nt change after Bound.
Thanks in advance
Re: QUdpSocket High rate message reading
That QueuedConnection looks wrong, any specific reason why you added it?
If the QUdpSocket is in the same thread as the receiver this just adds more delay, if they are on separate threads then the socket is used from two threads without concurrency protection.
Cheers,
_
Re: QUdpSocket High rate message reading
I mentioned it in my code
// the rate of receiving data is 10 msec if i don't put Qt::QueuedConnection, it didn't receive any more signal after first one. why ???
// change the rate of data to 1 sec and this code work well without Qt::QueuedConnection !!!
I see this bug report do you think its related? I m using Qt 5.6 on Windows 7
https://bugreports.qt.io/browse/QTBUG-46552
Re: QUdpSocket High rate message reading
Well, that bug should be fixed in your version, but it indeed sounds similar.
When you say your slot isn't called anymore, do you mean both slots or one specific, i.e. the data receive slot or the widget update slot?
Is there any interaction from the data processing to the widget?
Cheers,
_
Re: QUdpSocket High rate message reading
Quote:
Originally Posted by
anda_skoa
When you say your slot isn't called anymore, do you mean both slots or one specific, i.e. the data receive slot or the widget update slot?
No, just my socket received slot doesn't call any more, actually my widgets remained responsive and work well
Quote:
Originally Posted by
anda_skoa
Is there any interaction from the data processing to the widget?
No, When data received I just update some values in my class, and my widget just read this values each 100 ms from class and fill the form and update some charts
Added after 1 20 minutes:
How can I find if signals queue is full or not?
Re: QUdpSocket High rate message reading
Hi, I was wrong about my Qt version, it was Qt 5.5 and now I updated to 5.7 and everything works great now even without QueuedConnection and with default connection. thanks