美文网首页
QTcpSocket同步读取

QTcpSocket同步读取

作者: XBruce | 来源:发表于2021-01-26 13:23 被阅读0次

    QTimer timer;
    timer.setSingleShot(true);
    QEventLoop loop;
    loop.connect(socket, SIGNAL(readyRead()), SLOT(quit()));
    connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));

    while (resultBytes.size() < count)
    {
    timer.start(msTimeout);
    loop.exec();

    if(timer.isActive())
        resultBytes += socket->read(qMin(count, socket->bytesAvailable()));
    else
        break;
    

    }

    相关文章

      网友评论

          本文标题:QTcpSocket同步读取

          本文链接:https://www.haomeiwen.com/subject/kqegzktx.html