1
votes

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)
{
      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);

and my readBuffers code

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 
    }
}

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. I don't know how but my slot didn't signal anymore 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 didn't change after Bound.

Thanks in advance

1
Maybe your program is stuck in the while(udp_listener->hasPendingDatagrams()) loop?thuga
no my Gui is response to all type of signalsdanics
I found this and this bug report which seem related.thuga
@thuga actually I wrote this code in Qt 5.6 on a Windows 7 platform , but I think yes its related to this bug. what you think is a better implementation? give some advice in an answer so I mark your answer as a correct one. thanks for searchingdanics
I tested this on Windows 7 with Qt 5.5.1, and it worked fine no matter how fast I made it send the datagrams. I ran the sender and the listener on the same machine though, not sure if it matters.thuga

1 Answers

1
votes


Qt::QueuedConnection tells the signal to be added to the queue, not waiting for it to be treated before continuing.
If the work you do on the received data takes some time, maybe the sending rate is too much higher than the reading rate, resulting in a big signal queue so the qt system blocks the signal?

Don't have the time to test it, but what you say about changing data rate timer makes me think it could be something like that.

Maybe try to measure the time you need to process your data and try some different sending timer lengths to test if you can verify this idea.