如何使waitForBytesWritten调用无阻塞?

时间:2016-11-08 16:24:31

标签: qt qt4

我有这个功能:

bool TCPClient::sendPacket(Protocol::Packet &packet)
{
  if(this->tcpSocket->state() == QAbstractSocket::ConnectedState)
  {
    std::cout << "writing ..." << std::endl;
    std::cout << sizeof(BabelPacket) + packet.dataLength << std::endl;
    this->tcpSocket->write((const char *)&packet, sizeof(Protocol::BabelPacket) + packet.dataLength);
    return this->tcpSocket->waitForBytesWritten(-1);
  }
  else
  {
    std::cout << "socket close" << std::endl;
    return false;
  }
}

但是当我打电话时,它会阻止我的GUI。

您是否知道如何使此调用无阻塞,并且仍然触发readyRead信号?

由于

0 个答案:

没有答案