QUdpSocket:无法接收数据报 [英] QUdpSocket: Cannot receive datagram

查看:1859
本文介绍了QUdpSocket:无法接收数据报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用QUdpSocket为了从服务器接收数据。当我收到数据使用SFML它的工作,我可以通过SocketUdp接收数据,但与qt它不工作。

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;
}


推荐答案

绑定。可能在绑定后,readyRead在连接调用完成之前触发。如果不清空挂起的数据报,readyRead将不会再次触发。

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.

这篇关于QUdpSocket:无法接收数据报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆