Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Warning: hasPendingDatagrams called in UnconnectedState. Huh?
mnbv last edited by
Qt 4.8.0 on Windows.
I am attempting to read data with a QUdpSocket. The socket has been bound to a port with bind(). When I attempt to read datagrams in a loop, e.g.:
@ while (socket_.hasPendingDatagrams())
No datagrams are read (despite Wireshark showing data arriving with a correct destination port) and the console displays:
@QNativeSocketEngine::hasPendingDatagrams() was called in QAbstractSocket::UnconnectedState
Obviously hasPendingDatagrams() is called in UnconnectedState -- it's a UDP socket. It's never connected.
Additionally, when I try using the event loop instead, readyRead() is never emitted.
Using Winsock directly, I have no issues. I do not want to do that. Nothing about that console message makes sense, and everything I've done is 100% as per the documentation. How do I convince Qt that UDP sockets are supposed to be in UnconnectedState, and actually receive data on the socket? As it stands I have not been able to successfully use a QUdpSocket to perform the seemingly simple task of receiving data.
ChrisW67 last edited by
Have you bound the QUdpSocket to a port with QUdpSocket::bind()?
t3685 last edited by
Did you check the return value of bind()?
houmingc last edited by
how to check the return value of Qt bind()
Please, look at the function documentation. It returns a boolean value.