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. Pick-to: 6.2 6.3 6.4 Fixes: QTBUG-106392 Change-Id: Ie8f55dd0894cc5c8d683dd3c685980878956d3ca Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
parent
c1b198e013
commit
2a37ff2f49
|
@ -998,6 +998,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) {
|
||||
|
|
|
@ -919,10 +919,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();
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
import QtQml
|
||||
|
||||
|
||||
QtObject {
|
||||
id: root
|
||||
|
||||
component Test : QtObject {}
|
||||
|
||||
property alias myalias: other
|
||||
property var direct: Test { id: other }
|
||||
}
|
|
@ -96,6 +96,7 @@ private slots:
|
|||
void outerBindingOverridesInnerBinding();
|
||||
void aliasPropertyAndBinding();
|
||||
void aliasPropertyReset();
|
||||
void aliasPropertyToIC();
|
||||
void nonExistentAttachedObject();
|
||||
void scope();
|
||||
void importScope();
|
||||
|
@ -1913,6 +1914,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");
|
||||
|
|
Loading…
Reference in New Issue