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
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);
if(!udp_listener)
{
udp_listener = new QUdpSocket(this);
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);
To copy to clipboard, switch view to plain text mode
and my readBuffers 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
}
}
void readBuffers() {
QString buffer;
while(udp_listener->hasPendingDatagrams()) {
QByteArray received;
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
}
}
To copy to clipboard, switch view to plain text mode
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
Bookmarks