diff options
author | Andrei Golubev <andrei.golubev@qt.io> | 2021-12-21 16:49:51 +0100 |
---|---|---|
committer | Andrei Golubev <andrei.golubev@qt.io> | 2021-12-27 08:27:04 +0100 |
commit | 39aee682bf388e191a409485cbbe2e01996bc163 (patch) | |
tree | 571e078686af4cb789f930d5ba64e2836c94cb0b /tests/auto/qml/qqmlcomponent | |
parent | e659b5b23a75676627fb6dfb275c4eede24c086e (diff) |
qmltc: Support Component roots
It is a very special case that doesn't undergo a normal compilation but
instead just uses QQmlObjectCreator::createComponent() logic.
As QQmlObjectCreator::createComponent() returns a new QQmlComponent,
we can't use it within the qmltc-generated type's ctor. Instead, just
fake the same flow by incorporating the code into the qmltc type
setting
As a drive-by, fix the code to work correctly with Component roots.
This should now pretty much cover all the mystical logic of
QQmlComponentAndAliasResolver and, with tests, we can safely simplify
the qmltc code generator bits later without introducing bugs
Enhance tst_qqmlcomponent::componentTypes test to highlight that
property Component p: ComponentDerivedType {} is not marked with
QV4::CompiledData::Object::IsComponent flag at all and thus considered
to be an ordinary object binding, unlike
property Component p: NotComponentDerivedType {}
Pick-to: 6.3
Change-Id: I4ec41952d15f9659d316e44dab4050aa4908327c
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlcomponent')
-rw-r--r-- | tests/auto/qml/qqmlcomponent/data/ComponentType.qml | 4 | ||||
-rw-r--r-- | tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp | 17 |
2 files changed, 20 insertions, 1 deletions
diff --git a/tests/auto/qml/qqmlcomponent/data/ComponentType.qml b/tests/auto/qml/qqmlcomponent/data/ComponentType.qml index 1e6fa88216..dbad44b511 100644 --- a/tests/auto/qml/qqmlcomponent/data/ComponentType.qml +++ b/tests/auto/qml/qqmlcomponent/data/ComponentType.qml @@ -1,4 +1,6 @@ import QtQml Component { - QtObject {} // this is required + QtObject { // having a type inside Component is required + objectName: "enclosed" + } } diff --git a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp index 4f52661767..30be024217 100644 --- a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp +++ b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp @@ -1136,6 +1136,11 @@ void tst_qqmlcomponent::componentTypes() component.loadUrl(testFileUrl("ComponentType.qml")); QScopedPointer<QObject> o(component.create()); QVERIFY2(!o.isNull(), qPrintable(component.errorString())); + QQmlComponent *oComponent = qobject_cast<QQmlComponent *>(o.get()); + QVERIFY(oComponent); + QScopedPointer<QObject> enclosed(oComponent->create()); + QVERIFY(!enclosed.isNull()); + QCOMPARE(enclosed->objectName(), u"enclosed"_qs); } { @@ -1158,6 +1163,18 @@ void tst_qqmlcomponent::componentTypes() QVERIFY(!ctx->objectForName(u"inaccessible"_qs)); QVERIFY(ctx->objectForName(u"accessibleDelegate"_qs)); QVERIFY(!ctx->objectForName(u"inaccessibleDelegate"_qs)); + + QCOMPARE(qvariant_cast<QObject *>(o->property("p2"))->property("text").toString(), + u"foo"_qs); + auto p3Object = qvariant_cast<QObject *>(o->property("p3")); + QVERIFY(p3Object); + QVERIFY(p3Object->property("text").toString().isEmpty()); + + QQmlComponent *normalComponent = qobject_cast<QQmlComponent *>(normal); + QVERIFY(normalComponent); + QScopedPointer<QObject> enclosed(normalComponent->create()); + QVERIFY(enclosed); + QCOMPARE(enclosed->objectName(), u"enclosed"_qs); } } |