aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp')
-rw-r--r--tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp91
1 files changed, 49 insertions, 42 deletions
diff --git a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
index efd5bb571b..7c7c7d3bd0 100644
--- a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
+++ b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp
@@ -173,8 +173,8 @@ void tst_qqmlcomponent::qmlCreateWindow()
QQmlEngine engine;
QQmlComponent component(&engine);
component.loadUrl(testFileUrl("createWindow.qml"));
- QQuickWindow* window = qobject_cast<QQuickWindow *>(component.create());
- QVERIFY(window);
+ QScopedPointer<QQuickWindow> window(qobject_cast<QQuickWindow *>(component.create()));
+ QVERIFY(!window.isNull());
}
void tst_qqmlcomponent::qmlCreateObjectAutoParent_data()
@@ -192,8 +192,8 @@ void tst_qqmlcomponent::qmlCreateObjectAutoParent()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl(testFile));
- QQuickItem *root = qobject_cast<QQuickItem *>(component.create());
- QVERIFY(root);
+ QScopedPointer<QObject> root(qobject_cast<QQuickItem *>(component.create()));
+ QVERIFY(!root.isNull());
QObject *qtobjectParent = root->property("qtobjectParent").value<QObject*>();
QQuickItem *itemParent = qobject_cast<QQuickItem *>(root->property("itemParent").value<QObject*>());
QQuickWindow *windowParent = qobject_cast<QQuickWindow *>(root->property("windowParent").value<QObject*>());
@@ -251,45 +251,52 @@ void tst_qqmlcomponent::qmlCreateObjectWithProperties()
QQmlEngine engine;
QQmlComponent component(&engine, testFileUrl("createObjectWithScript.qml"));
QVERIFY2(component.errorString().isEmpty(), component.errorString().toUtf8());
- QObject *object = component.create();
- QVERIFY(object != nullptr);
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY(!object.isNull());
- QObject *testObject1 = object->property("declarativerectangle").value<QObject*>();
- QVERIFY(testObject1);
- QCOMPARE(testObject1->parent(), object);
- QCOMPARE(testObject1->property("x").value<int>(), 17);
- QCOMPARE(testObject1->property("y").value<int>(), 17);
- QCOMPARE(testObject1->property("color").value<QColor>(), QColor(255,255,255));
- QCOMPARE(QQmlProperty::read(testObject1,"border.width").toInt(), 3);
- QCOMPARE(QQmlProperty::read(testObject1,"innerRect.border.width").toInt(), 20);
- delete testObject1;
-
- QObject *testObject2 = object->property("declarativeitem").value<QObject*>();
- QVERIFY(testObject2);
- QCOMPARE(testObject2->parent(), object);
- //QCOMPARE(testObject2->metaObject()->className(), "QDeclarativeItem_QML_2");
- QCOMPARE(testObject2->property("x").value<int>(), 17);
- QCOMPARE(testObject2->property("y").value<int>(), 17);
- QCOMPARE(testObject2->property("testBool").value<bool>(), true);
- QCOMPARE(testObject2->property("testInt").value<int>(), 17);
- QCOMPARE(testObject2->property("testObject").value<QObject*>(), object);
- delete testObject2;
-
- QObject *testBindingObj = object->property("bindingTestObject").value<QObject*>();
- QVERIFY(testBindingObj);
- QCOMPARE(testBindingObj->parent(), object);
- QCOMPARE(testBindingObj->property("testValue").value<int>(), 300);
- object->setProperty("width", 150);
- QCOMPARE(testBindingObj->property("testValue").value<int>(), 150 * 3);
- delete testBindingObj;
-
- QObject *testBindingThisObj = object->property("bindingThisTestObject").value<QObject*>();
- QVERIFY(testBindingThisObj);
- QCOMPARE(testBindingThisObj->parent(), object);
- QCOMPARE(testBindingThisObj->property("testValue").value<int>(), 900);
- testBindingThisObj->setProperty("width", 200);
- QCOMPARE(testBindingThisObj->property("testValue").value<int>(), 200 * 3);
- delete testBindingThisObj;
+ {
+ QScopedPointer<QObject> testObject1(object->property("declarativerectangle")
+ .value<QObject*>());
+ QVERIFY(testObject1);
+ QCOMPARE(testObject1->parent(), object.data());
+ QCOMPARE(testObject1->property("x").value<int>(), 17);
+ QCOMPARE(testObject1->property("y").value<int>(), 17);
+ QCOMPARE(testObject1->property("color").value<QColor>(), QColor(255,255,255));
+ QCOMPARE(QQmlProperty::read(testObject1.data(),"border.width").toInt(), 3);
+ QCOMPARE(QQmlProperty::read(testObject1.data(),"innerRect.border.width").toInt(), 20);
+ }
+
+ {
+ QScopedPointer<QObject> testObject2(object->property("declarativeitem").value<QObject*>());
+ QVERIFY(testObject2);
+ QCOMPARE(testObject2->parent(), object.data());
+ //QCOMPARE(testObject2->metaObject()->className(), "QDeclarativeItem_QML_2");
+ QCOMPARE(testObject2->property("x").value<int>(), 17);
+ QCOMPARE(testObject2->property("y").value<int>(), 17);
+ QCOMPARE(testObject2->property("testBool").value<bool>(), true);
+ QCOMPARE(testObject2->property("testInt").value<int>(), 17);
+ QCOMPARE(testObject2->property("testObject").value<QObject*>(), object.data());
+ }
+
+ {
+ QScopedPointer<QObject> testBindingObj(object->property("bindingTestObject")
+ .value<QObject*>());
+ QVERIFY(testBindingObj);
+ QCOMPARE(testBindingObj->parent(), object.data());
+ QCOMPARE(testBindingObj->property("testValue").value<int>(), 300);
+ object->setProperty("width", 150);
+ QCOMPARE(testBindingObj->property("testValue").value<int>(), 150 * 3);
+ }
+
+ {
+ QScopedPointer<QObject> testBindingThisObj(object->property("bindingThisTestObject")
+ .value<QObject*>());
+ QVERIFY(testBindingThisObj);
+ QCOMPARE(testBindingThisObj->parent(), object.data());
+ QCOMPARE(testBindingThisObj->property("testValue").value<int>(), 900);
+ testBindingThisObj->setProperty("width", 200);
+ QCOMPARE(testBindingThisObj->property("testValue").value<int>(), 200 * 3);
+ }
}
void tst_qqmlcomponent::qmlCreateParentReference()