大家好!QUdpSocket高速邮件阅读
我与QUdpSocket提供和readyRead信号工作的一个奇怪的问题,我可以说,它不工作,因为我认为,
我创建了一个QUdpSocket提供并将其绑定到某个端口时,readyRead信号连接到我的插槽,我读了所有悬而未决的数据报如下
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);
和我readBuffers代码
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
}
}
我想使用的Qt :: QueuedConne解决了我的问题但今天我在我的项目中添加了另一个小部件并每100毫秒更新一次。我不知道如何,但2秒后我的插槽没有再发出信号。
如果我改变我的计时器间隔或发送数据速率到1秒,一切都很好。
所有我的类和我的小部件住在主程序的线程中,我不使用另一个线程,但它似乎我应该!
那么为什么Qt eventloop会丢失信号?
我检查我的套接字状态,并且在绑定后没有改变。
在此先感谢
也许你的程序卡在'while(udp_listener-> hasPendingDatagrams())'循环中? – thuga
没有我的桂是响应所有类型的信号 – danics
我发现[this](https://bugreports.qt.io/browse/QTBUG-46552)和[此错误报告](https://bugreports.qt.io /浏览/ QTBUG-48556)这似乎有关。 – thuga