Use QTimer as object member rather than pointer based.

Avoid crashes if timer is zero.
This commit is contained in:
Klaas Freitag 2014-03-25 10:58:57 +01:00
parent 6e6f647c63
commit 11bbad79e2
2 changed files with 14 additions and 15 deletions

View File

@ -46,8 +46,10 @@ AbstractNetworkJob::AbstractNetworkJob(Account *account, const QString &path, QO
, _reply(0)
, _account(account)
, _path(path)
, _timer(0)
{
_timer.setSingleShot(true);
_timer.setInterval(10*1000); // default to 10 seconds.
connect(&_timer, SIGNAL(timeout()), this, SLOT(slotTimeout()));
}
void AbstractNetworkJob::setReply(QNetworkReply *reply)
@ -61,21 +63,15 @@ void AbstractNetworkJob::setReply(QNetworkReply *reply)
void AbstractNetworkJob::setTimeout(qint64 msec)
{
qDebug() << Q_FUNC_INFO << msec;
if (_timer)
_timer->deleteLater();
_timer = new QTimer(this);
_timer->setSingleShot(true);
connect(_timer, SIGNAL(timeout()), this, SLOT(slotTimeout()));
_timer->start(msec);
_timer.start(msec);
}
void AbstractNetworkJob::resetTimeout()
{
if( _timer ) {
qint64 interval = _timer->interval();
_timer->stop();
_timer->start(interval);
}
qint64 interval = _timer.interval();
_timer.stop();
_timer.start(interval);
}
void AbstractNetworkJob::setIgnoreCredentialFailure(bool ignore)
@ -100,7 +96,7 @@ void AbstractNetworkJob::setupConnections(QNetworkReply *reply)
QNetworkReply* AbstractNetworkJob::addTimer(QNetworkReply *reply)
{
reply->setProperty("timer", QVariant::fromValue(_timer));
reply->setProperty("timer", QVariant::fromValue(&_timer));
return reply;
}
@ -169,6 +165,9 @@ AbstractNetworkJob::~AbstractNetworkJob() {
void AbstractNetworkJob::start()
{
_timer.start();
_durationTimer.start();
qDebug() << "!!!" << metaObject()->className() << "created for" << account()->url() << "querying" << path();
}

View File

@ -20,9 +20,9 @@
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QPointer>
#include <QTimer>
class QUrl;
class QTimer;
namespace Mirall {
@ -94,7 +94,7 @@ private:
QNetworkReply *_reply;
Account *_account;
QString _path;
QTimer *_timer;
QTimer _timer;
};
/**