#include "qreplytimeout.h"
#include <QTimer>
#include <QNetworkReply>

QReplyTimeout::QReplyTimeout(QNetworkReply *reply, const int timeout) : QObject(reply)
{
    if (reply && reply->isRunning()) {  // 启动单次定时器
        QTimer::singleShot(timeout, this, SLOT(onTimeout()));
    }
}

void QReplyTimeout::onTimeout()
{
    QNetworkReply *reply = static_cast<QNetworkReply*>(parent());
    if (reply->isRunning()) {
        reply->abort();
        reply->deleteLater();
        Q_EMIT timeout();
    }
}

