I am using QUdpSocket in order to receive data from a server. When i receive data With SFML its working, i can receive data throught SocketUdp but with qt it doesn't work.
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;
}
解决方案
I would make the connect before the bind. It's possible that after binding, the readyRead fires before the connect call is completed. If you don't empty the pending datagrams, the readyRead will not fire again.