aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-05-09 17:49:17 +0200
committerUlf Hermann <ulf.hermann@qt.io>2022-05-11 10:06:38 +0200
commitcf9c0f0180b65f0f2ad2cf20a35a3d11a7430927 (patch)
tree8a6c8a475412863c3fa595e98ed163075c3c6304 /tests
parentcc902136c6693b14ac98e41046a2bfecc8f5911b (diff)
Avoid memory leaks in QQuickListView and tst_qqmlinstantiator
Pick-to: 6.2 6.3 Change-Id: Ieceffedb082e893b54bcda99076df3ccdeff6010 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qqmlinstantiator/tst_qqmlinstantiator.cpp24
1 files changed, 15 insertions, 9 deletions
diff --git a/tests/auto/qml/qqmlinstantiator/tst_qqmlinstantiator.cpp b/tests/auto/qml/qqmlinstantiator/tst_qqmlinstantiator.cpp
index a0ab2cda5b..3723b56de9 100644
--- a/tests/auto/qml/qqmlinstantiator/tst_qqmlinstantiator.cpp
+++ b/tests/auto/qml/qqmlinstantiator/tst_qqmlinstantiator.cpp
@@ -69,7 +69,8 @@ void tst_qqmlinstantiator::createNone()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("createNone.qml"));
- QQmlInstantiator *instantiator = qobject_cast<QQmlInstantiator*>(component.create());
+ QScopedPointer<QObject> o(component.create());
+ QQmlInstantiator *instantiator = qobject_cast<QQmlInstantiator*>(o.data());
QVERIFY(instantiator != nullptr);
QCOMPARE(instantiator->isActive(), true);
QCOMPARE(instantiator->count(), 0);
@@ -81,7 +82,8 @@ void tst_qqmlinstantiator::createSingle()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("createSingle.qml"));
- QQmlInstantiator *instantiator = qobject_cast<QQmlInstantiator*>(component.create());
+ QScopedPointer<QObject> o(component.create());
+ QQmlInstantiator *instantiator = qobject_cast<QQmlInstantiator*>(o.data());
QVERIFY(instantiator != nullptr);
QCOMPARE(instantiator->isActive(), true);
QCOMPARE(instantiator->count(), 1);
@@ -98,7 +100,8 @@ void tst_qqmlinstantiator::createMultiple()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("createMultiple.qml"));
- QQmlInstantiator *instantiator = qobject_cast<QQmlInstantiator*>(component.create());
+ QScopedPointer<QObject> o(component.create());
+ QQmlInstantiator *instantiator = qobject_cast<QQmlInstantiator*>(o.data());
QVERIFY(instantiator != nullptr);
QCOMPARE(instantiator->isActive(), true);
QCOMPARE(instantiator->count(), 10);
@@ -116,7 +119,8 @@ void tst_qqmlinstantiator::stringModel()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("stringModel.qml"));
- QQmlInstantiator *instantiator = qobject_cast<QQmlInstantiator*>(component.create());
+ QScopedPointer<QObject> o(component.create());
+ QQmlInstantiator *instantiator = qobject_cast<QQmlInstantiator*>(o.data());
QVERIFY(instantiator != nullptr);
QCOMPARE(instantiator->isActive(), true);
QCOMPARE(instantiator->count(), 4);
@@ -133,7 +137,8 @@ void tst_qqmlinstantiator::activeProperty()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("inactive.qml"));
- QQmlInstantiator *instantiator = qobject_cast<QQmlInstantiator*>(component.create());
+ QScopedPointer<QObject> o(component.create());
+ QQmlInstantiator *instantiator = qobject_cast<QQmlInstantiator*>(o.data());
QVERIFY(instantiator != nullptr);
QSignalSpy activeSpy(instantiator, SIGNAL(activeChanged()));
QSignalSpy countSpy(instantiator, SIGNAL(countChanged()));
@@ -188,7 +193,8 @@ void tst_qqmlinstantiator::intModelChange()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("createMultiple.qml"));
- QQmlInstantiator *instantiator = qobject_cast<QQmlInstantiator*>(component.create());
+ QScopedPointer<QObject> o(component.create());
+ QQmlInstantiator *instantiator = qobject_cast<QQmlInstantiator*>(o.data());
QVERIFY(instantiator != nullptr);
QSignalSpy activeSpy(instantiator, SIGNAL(activeChanged()));
QSignalSpy countSpy(instantiator, SIGNAL(countChanged()));
@@ -224,7 +230,7 @@ void tst_qqmlinstantiator::createAndRemove()
QScopedPointer<StringModel> model {new StringModel("model1")};
qmlRegisterSingletonInstance("Test", 1, 0, "Model1", model.get());
QQmlComponent component(&engine, testFileUrl("createAndRemove.qml"));
- QObject *rootObject = component.create();
+ QScopedPointer<QObject> rootObject(component.create());
QVERIFY(rootObject != nullptr);
QQmlInstantiator *instantiator =
@@ -282,12 +288,12 @@ void tst_qqmlinstantiator::handlerWithParent()
{
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("handlerWithParent.qml"));
- QObject *rootObject = component.create();
+ QScopedPointer<QObject> rootObject(component.create());
QVERIFY(rootObject != nullptr);
const auto handlers = rootObject->findChildren<QObject *>("pointHandler");
QCOMPARE(handlers.count(), 2);
for (const auto *h : handlers) {
- QCOMPARE(h->parent(), rootObject);
+ QCOMPARE(h->parent(), rootObject.data());
}
}