aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmltimer
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2024-01-25 15:17:19 +0100
committerUlf Hermann <ulf.hermann@qt.io>2024-01-25 18:35:05 +0100
commit655996fd0e7b30f29cc081bf667fed0a78380179 (patch)
treee00dac120da7a0925e0dec40652f578b1e5fe11f /tests/auto/qml/qqmltimer
parentd7a98cb65f51891ee6408c6d5ef64114a241c5c6 (diff)
tst_qqmltimer: Avoid memory leaks
Change-Id: Idc7a3600fdd1168e4f3634c73fa0fa5603348e73 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmltimer')
-rw-r--r--tests/auto/qml/qqmltimer/tst_qqmltimer.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/tests/auto/qml/qqmltimer/tst_qqmltimer.cpp b/tests/auto/qml/qqmltimer/tst_qqmltimer.cpp
index cadc308961..587c85094c 100644
--- a/tests/auto/qml/qqmltimer/tst_qqmltimer.cpp
+++ b/tests/auto/qml/qqmltimer/tst_qqmltimer.cpp
@@ -69,7 +69,8 @@ void tst_qqmltimer::notRepeating()
QQmlEngine engine;
QQmlComponent component(&engine);
component.setData(QByteArray("import QtQml 2.0\nTimer { interval: 100; running: true }"), QUrl::fromLocalFile(""));
- QQmlTimer *timer = qobject_cast<QQmlTimer*>(component.create());
+ std::unique_ptr<QObject> o { component.create() };
+ QQmlTimer *timer = qobject_cast<QQmlTimer*>(o.get());
QVERIFY(timer != nullptr);
QVERIFY(timer->isRunning());
QVERIFY(!timer->isRepeating());
@@ -355,7 +356,8 @@ void tst_qqmltimer::stopWhenEventPosted()
QQmlEngine engine;
QQmlComponent component(&engine);
component.setData(QByteArray("import QtQml 2.0\nTimer { interval: 200; running: true }"), QUrl::fromLocalFile(""));
- QQmlTimer *timer = qobject_cast<QQmlTimer*>(component.create());
+ std::unique_ptr<QObject> o { component.create() };
+ QQmlTimer *timer = qobject_cast<QQmlTimer*>(o.get());
TimerHelper helper;
connect(timer, SIGNAL(triggered()), &helper, SLOT(timeout()));
@@ -379,7 +381,8 @@ void tst_qqmltimer::restartWhenEventPosted()
QQmlEngine engine;
QQmlComponent component(&engine);
component.setData(QByteArray("import QtQml 2.0\nTimer { interval: 200; running: true }"), QUrl::fromLocalFile(""));
- QQmlTimer *timer = qobject_cast<QQmlTimer*>(component.create());
+ std::unique_ptr<QObject> o { component.create() };
+ QQmlTimer *timer = qobject_cast<QQmlTimer*>(o.get());
TimerHelper helper;
connect(timer, SIGNAL(triggered()), &helper, SLOT(timeout()));