gpt4 book ai didi

qt - QSslSocket waitForReadyRead 似乎没有工作

转载 作者:太空宇宙 更新时间:2023-11-03 14:59:02 26 4
gpt4 key购买 nike

这是我编写的同步 TCP 客户端中 read() 语句上方的一小段代码。

    std::cout << "available? " << socket->bytesAvailable() << std::endl;
socket->waitForReadyRead();
std::cout << "reading..." << std::endl;
bytesRead = socket->read(message + totalBytesRead, messageSize - totalBytesRead);

下面一行:

socket->bytesAvailable()

返回 4,显然有数据可供读取。我遇到的问题是 waitForReadyRead() 一直阻塞到默认超时 30 秒。 Read() 然后继续读取下一行中的 0 个字节。

那么如果有字节可供读取,为什么 waitForReadyRead() 会阻塞

最佳答案

来自 QIODevice::waitForReadyRead 文档:

Blocks until new data is available for reading and the readyRead() signal has been emitted, or until msecs milliseconds have passed. If msecs is -1, this function will not time out.

Returns true if new data is available for reading; otherwise returns false (if the operation timed out or if an error occurred).

处理网络连接的最佳原因是使用信号/插槽机制(异步原因)

关于qt - QSslSocket waitForReadyRead 似乎没有工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25316268/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com