我正在使用QUdpSocket以接收來自服務器的數據。當我使用SFML接收數據時,我可以通過SocketUdp接收數據,但是使用qt它不起作用。QUdpSocket:無法接收數據報
void TheClass::Bind()
{
m_sock_receive = new QUdpSocket(this);
if (m_sock_receive->bind(QHostAddress::Any, port))
{
std::cout << "Bind: OK" << std::endl;
connect(m_sock_receive, SIGNAL(readyRead()), this, SLOT(QtReceive()));
}
else
std::cout << "Bind: NOK" << std::endl;
}
void TheClass::QtReceive()
{
std::cout << "Pending data !" << std::endl;
}
閱讀QT 4.8.6源代碼如果成功,我會看到BoundState立即在bind()函數中設置。請親自看看:https://github.com/qt/qt/blob/4.8/src/network/socket/qudpsocket.cpp#L265 –