12345678910111213141516171819202122232425262728293031 |
- #ifndef QREPLYTIMEOUT_H
- #define QREPLYTIMEOUT_H
- #include <QObject>
- #include <QTimer>
- #include <QNetworkReply>
- #include <stdio.h>
- class QReplayTimeout : public QObject {
- Q_OBJECT
- public:
- QReplayTimeout(QNetworkReply *reply, const int timeout) :QObject(reply) {
- Q_ASSERT(reply);
- if( reply && reply->isRunning()){
- QTimer::singleShot(timeout,this,SLOT(onTimeout()));
- }
- }
- signals:
- void net_timeout();
- private slots:
- void onTimeout(){
- QNetworkReply *reply = static_cast<QNetworkReply *>(parent());
- if(reply->isRunning()){
- reply->abort();
- reply->deleteLater();
- emit net_timeout();
- }
- }
- };
- #endif // QREPLYTIMEOUT_H
|