QTimer: extend property tests and fix binding loop
The bindable property tests were not using the QTestPrivate helpers, so
add a new test which uses them.
The new tests revealed a binding loop for the interval property.
Fix it in a usual way by explicitly removing the binding and using
{set}ValueBypassingBindings() in the setter.
Task-number: QTBUG-116346
Pick-to: 6.6 6.5
Change-Id: If94f57938da449a68e3527aead5ebd55ba410adb
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
bb10
parent
cdb50edc98
commit
7d70edd31c
|
|
@ -630,8 +630,9 @@ QBindable<bool> QTimer::bindableSingleShot()
|
|||
void QTimer::setInterval(int msec)
|
||||
{
|
||||
Q_D(QTimer);
|
||||
const bool intervalChanged = msec != d->inter;
|
||||
d->inter.setValue(msec);
|
||||
d->inter.removeBindingUnlessInWrapper();
|
||||
const bool intervalChanged = msec != d->inter.valueBypassingBindings();
|
||||
d->inter.setValueBypassingBindings(msec);
|
||||
if (d->id != QTimerPrivate::INV_TIMER) { // create new timer
|
||||
QObject::killTimer(d->id); // restart timer
|
||||
d->id = QObject::startTimer(std::chrono::milliseconds{msec}, d->type);
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ qt_internal_add_test(tst_qtimer
|
|||
tst_qtimer.cpp
|
||||
LIBRARIES
|
||||
Qt::CorePrivate
|
||||
Qt::TestPrivate
|
||||
)
|
||||
|
||||
if(QT_FEATURE_glib AND UNIX)
|
||||
|
|
@ -26,5 +27,6 @@ if(QT_FEATURE_glib AND UNIX)
|
|||
DISABLE_GLIB
|
||||
LIBRARIES
|
||||
Qt::CorePrivate
|
||||
Qt::TestPrivate
|
||||
)
|
||||
endif()
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
#include <QtCore/private/qglobal_p.h>
|
||||
#include <QTest>
|
||||
#include <QSignalSpy>
|
||||
#include <QtTest/private/qpropertytesthelper_p.h>
|
||||
|
||||
#include <qtimer.h>
|
||||
#include <qthread.h>
|
||||
|
|
@ -89,6 +90,7 @@ private slots:
|
|||
|
||||
void bindToTimer();
|
||||
void bindTimer();
|
||||
void automatedBindingTests();
|
||||
};
|
||||
|
||||
void tst_QTimer::zeroTimer()
|
||||
|
|
@ -1326,6 +1328,42 @@ void tst_QTimer::bindTimer()
|
|||
QCOMPARE(timer.timerType(), Qt::VeryCoarseTimer);
|
||||
}
|
||||
|
||||
void tst_QTimer::automatedBindingTests()
|
||||
{
|
||||
QTimer timer;
|
||||
|
||||
QVERIFY(!timer.isSingleShot());
|
||||
QTestPrivate::testReadWritePropertyBasics(timer, true, false, "singleShot");
|
||||
if (QTest::currentTestFailed()) {
|
||||
qDebug("Failed property test for QTimer::singleShot");
|
||||
return;
|
||||
}
|
||||
|
||||
QCOMPARE_NE(timer.interval(), 10);
|
||||
QTestPrivate::testReadWritePropertyBasics(timer, 10, 20, "interval");
|
||||
if (QTest::currentTestFailed()) {
|
||||
qDebug("Failed property test for QTimer::interval");
|
||||
return;
|
||||
}
|
||||
|
||||
QCOMPARE_NE(timer.timerType(), Qt::PreciseTimer);
|
||||
QTestPrivate::testReadWritePropertyBasics(timer, Qt::PreciseTimer, Qt::CoarseTimer,
|
||||
"timerType");
|
||||
if (QTest::currentTestFailed()) {
|
||||
qDebug("Failed property test for QTimer::timerType");
|
||||
return;
|
||||
}
|
||||
|
||||
timer.start(1000);
|
||||
QVERIFY(timer.isActive());
|
||||
QTestPrivate::testReadOnlyPropertyBasics(timer, true, false, "active",
|
||||
[&timer]() { timer.stop(); });
|
||||
if (QTest::currentTestFailed()) {
|
||||
qDebug("Failed property test for QTimer::active");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
class OrderHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ qt_internal_add_test(tst_qguitimer
|
|||
LIBRARIES
|
||||
Qt::CorePrivate
|
||||
Qt::Gui
|
||||
Qt::TestPrivate
|
||||
)
|
||||
|
||||
if(QT_FEATURE_glib AND UNIX)
|
||||
|
|
@ -29,5 +30,6 @@ if(QT_FEATURE_glib AND UNIX)
|
|||
LIBRARIES
|
||||
Qt::CorePrivate
|
||||
Qt::Gui
|
||||
Qt::TestPrivate
|
||||
)
|
||||
endif()
|
||||
|
|
|
|||
Loading…
Reference in New Issue