QT网络请求超时处理

    QTimer timer;
    timer.setSingleShot(true);
 
    QEventLoop loop;
    connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
    connect(m_reply, SIGNAL(finished()), &loop, SLOT(quit()));
    timer.start(10000);   // 10 secs. timeout
    loop.exec();

    if(timer.isActive()) {
        timer.stop();
    } else {
       disconnect(m_reply, SIGNAL(finished()), &loop, SLOT(quit()));
       txt_miner_output->append("reply timeout");

       m_reply->abort();
       m_reply->close();
       m_reply->deleteLater();
    }

 

你可能感兴趣的:(QT网络请求超时处理)