大家好!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