aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2022-09-08 13:59:15 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-09-08 19:16:24 +0000
commitf604543d53b98370b0a12953a889fc971c983522 (patch)
tree5172019572f45736f2dda2b21b24ddf2f8292fe6
parent64fba2938ab08c12936d3b0d12c34f1bedb98e89 (diff)
Fix alias to inline component type
When we create an alias property, we resolve its targets metatype. In the case of inline components of the same file, that's however not possible via QQmlType, as the type will only be available once the outer type has been fully set up. Fix this by looking up the type in the ExecutableCompilationUnit, where the information is available while the type registraiton process is still ongoing. As a drive-by, also set the alias flag correctly when constructing the QMetaObject of a QML element. Fixes: QTBUG-106392 Change-Id: Ie8f55dd0894cc5c8d683dd3c685980878956d3ca Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit 2a37ff2f49140272d0122ccc097cc14c2fa4133e) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/qml/qml/qqmlpropertycache.cpp1
-rw-r--r--src/qml/qml/qqmlpropertycachecreator_p.h10
-rw-r--r--tests/auto/qml/qqmlecmascript/data/aliasPropertyToIC.qml11
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp19
4 files changed, 39 insertions, 2 deletions
diff --git a/src/qml/qml/qqmlpropertycache.cpp b/src/qml/qml/qqmlpropertycache.cpp
index 5b44ead713..278977fb9c 100644
--- a/src/qml/qml/qqmlpropertycache.cpp
+++ b/src/qml/qml/qqmlpropertycache.cpp
@@ -1038,6 +1038,7 @@ void QQmlPropertyCache::toMetaObjectBuilder(QMetaObjectBuilder &builder) const
property.setWritable(data->isWritable());
property.setResettable(data->isResettable());
property.setBindable(data->isBindable());
+ property.setAlias(data->isAlias());
}
for (int ii = 0; ii < methods.count(); ++ii) {
diff --git a/src/qml/qml/qqmlpropertycachecreator_p.h b/src/qml/qml/qqmlpropertycachecreator_p.h
index c8d516b367..09d8ace425 100644
--- a/src/qml/qml/qqmlpropertycachecreator_p.h
+++ b/src/qml/qml/qqmlpropertycachecreator_p.h
@@ -945,10 +945,16 @@ inline QQmlError QQmlPropertyCacheAliasCreator<ObjectContainer>::propertyDataFor
}
const auto referencedType = typeRef->type();
- if (referencedType.isValid())
+ if (referencedType.isValid()) {
*type = referencedType.typeId();
- else
+ if (!type->isValid() && referencedType.isInlineComponentType()) {
+ int objectId = referencedType.inlineComponentId();
+ *type = objectContainer->typeIdsForComponent(objectId).id;
+ Q_ASSERT(type->isValid());
+ }
+ } else {
*type = typeRef->compilationUnit()->typeIds.id;
+ }
*version = typeRef->version();
diff --git a/tests/auto/qml/qqmlecmascript/data/aliasPropertyToIC.qml b/tests/auto/qml/qqmlecmascript/data/aliasPropertyToIC.qml
new file mode 100644
index 0000000000..17116bb091
--- /dev/null
+++ b/tests/auto/qml/qqmlecmascript/data/aliasPropertyToIC.qml
@@ -0,0 +1,11 @@
+import QtQml
+
+
+QtObject {
+ id: root
+
+ component Test : QtObject {}
+
+ property alias myalias: other
+ property var direct: Test { id: other }
+}
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index 547ccf4635..c68fc1019f 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -119,6 +119,7 @@ private slots:
void outerBindingOverridesInnerBinding();
void aliasPropertyAndBinding();
void aliasPropertyReset();
+ void aliasPropertyToIC();
void nonExistentAttachedObject();
void scope();
void importScope();
@@ -1935,6 +1936,24 @@ void tst_qqmlecmascript::aliasPropertyReset()
QCOMPARE(object->property("aliasedIntIsUndefined"), QVariant(false));
}
+void tst_qqmlecmascript::aliasPropertyToIC()
+{
+ QQmlEngine engine;
+ std::unique_ptr<QObject> root;
+
+ // test that a manual write (of undefined) to a resettable aliased property succeeds
+ QQmlComponent c(&engine, testFileUrl("aliasPropertyToIC.qml"));
+ root.reset(c.create());
+ QVERIFY(root);
+ auto mo = root->metaObject();
+ int aliasIndex = mo->indexOfProperty("myalias");
+ auto prop = mo->property(aliasIndex);
+ QVERIFY(prop.isAlias());
+ auto fromAlias = prop.read(root.get()).value<QObject *>();
+ auto direct = root->property("direct").value<QObject *>();
+ QCOMPARE(fromAlias, direct);
+}
+
void tst_qqmlecmascript::componentCreation_data()
{
QTest::addColumn<QString>("method");