From 107a5017149f8dbe7829e8e6d03a0e7a1124f281 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sun, 11 Sep 2016 20:10:34 +0900 Subject: Explicitly stop the timer in finishJob() This should avoid timeout event catching up on a not-yet-deleted-but- already-invalid job object. --- jobs/basejob.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'jobs/basejob.cpp') diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp index 20b45a15..a3b69922 100644 --- a/jobs/basejob.cpp +++ b/jobs/basejob.cpp @@ -52,6 +52,8 @@ class BaseJob::Private QScopedPointer reply; Status status; + + QTimer timer; }; inline QDebug operator<<(QDebug dbg, BaseJob* j) @@ -63,6 +65,7 @@ BaseJob::BaseJob(ConnectionData* connection, JobHttpType type, QString name, boo : d(new Private(connection, type, needsToken)) { setObjectName(name); + connect (&d->timer, &QTimer::timeout, this, &BaseJob::timeout); qDebug() << this << "created"; } @@ -115,7 +118,7 @@ void BaseJob::start() } connect( d->reply.data(), &QNetworkReply::sslErrors, this, &BaseJob::sslErrors ); connect( d->reply.data(), &QNetworkReply::finished, this, &BaseJob::gotReply ); - QTimer::singleShot( 120*1000, this, SLOT(timeout()) ); + d->timer.start( 120*1000 ); // connect( d->reply, static_cast(&QNetworkReply::error), // this, &BaseJob::networkError ); // http://doc.qt.io/qt-5/qnetworkreply.html#error-1 } @@ -163,6 +166,7 @@ BaseJob::Status BaseJob::parseJson(const QJsonDocument&) void BaseJob::finishJob(bool emitResult) { + d->timer.stop(); if (!d->reply) { qWarning() << this << "finishes with empty network reply"; -- cgit v1.2.3