Safer setting of interval in QTimer

There are two methods which set the interval and do things
afterwards. Setting the interval might trigger other code. This
patch uses setValueBypassingBindings and marks the interval dirty
later, just to be safe.

Change-Id: I2cae3e4a9f040007dfd246c424250034e8df10a0
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
This commit is contained in:
Andreas Buhr 2021-01-28 10:54:42 +01:00
parent 1a2dd92767
commit a7ca8b1a28

View File

@ -257,8 +257,9 @@ void QTimer::start()
void QTimer::start(int msec) void QTimer::start(int msec)
{ {
Q_D(QTimer); Q_D(QTimer);
d->inter = msec; d->inter.setValueBypassingBindings(msec);
start(); start();
d->inter.markDirty();
} }
@ -752,13 +753,14 @@ QBindable<bool> QTimer::bindableSingleShot()
void QTimer::setInterval(int msec) void QTimer::setInterval(int msec)
{ {
Q_D(QTimer); Q_D(QTimer);
d->inter = msec; d->inter.setValueBypassingBindings(msec);
if (d->id != INV_TIMER) { // create new timer if (d->id != INV_TIMER) { // create new timer
QObject::killTimer(d->id); // restart timer QObject::killTimer(d->id); // restart timer
d->id = QObject::startTimer(msec, d->type); d->id = QObject::startTimer(msec, d->type);
// No need to call markDirty() for d->isActiveData here, // No need to call markDirty() for d->isActiveData here,
// as timer state actually does not change // as timer state actually does not change
} }
d->inter.markDirty();
} }
int QTimer::interval() const int QTimer::interval() const