Warning: hasPendingDatagrams called in UnconnectedState. Huh?
-
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())
socket_.readDatagram(data, sizeof(data));
@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.
-
Please, look at the function documentation. It returns a boolean value.