QTcpSocket同步读取

2021-01-26  本文已影响0人  XBruce

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;

}

上一篇下一篇

猜你喜欢

热点阅读