From 2ec852ada2a51e1da47a2ccbb93104fc7938bfc4 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 30 Sep 2013 05:52:31 +0200 Subject: [PATCH] Fix composite type registration in the new compiler When setting a property of a composite type like this property MyType foo: MyType {} and MyType.qml defines the new type, we test for assignability of MyType to the property foo. This test happens before MyType is instantiated and it relies on the meta-type in the CompiledData being set. Therefore this patch makes sure that the meta-type and the list meta-type are set accordingly at type compilation time, not instantiation time, similar to how it's done in the VME. Change-Id: Id7231e0a0113fa63ba6508bfbb1565dd554c5e56 Reviewed-by: Lars Knoll --- src/qml/qml/qqmlcompiler_p.h | 1 + src/qml/qml/qqmlobjectcreator.cpp | 2 -- src/qml/qml/qqmltypeloader.cpp | 17 +++++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/qml/qml/qqmlcompiler_p.h b/src/qml/qml/qqmlcompiler_p.h index 9e63ecb..475e438 100644 --- a/src/qml/qml/qqmlcompiler_p.h +++ b/src/qml/qml/qqmlcompiler_p.h @@ -145,6 +145,7 @@ public: QHash objectIndexToIdForRoot; bool isComponent(int objectIndex) const { return objectIndexToIdPerComponent.contains(objectIndex); } + bool isCompositeType() const { return !datas.at(qmlUnit->indexOfRootObject).isEmpty(); } // --- struct Instruction { diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index 55858e0..c320ca9 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -542,8 +542,6 @@ QObject *QmlObjectCreator::create(int subComponentIndex, QObject *parent) ddata->compiledData->addref(); context->contextObject = instance; - - QQmlEnginePrivate::get(engine)->registerInternalCompositeType(compiledData); } return instance; } diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp index 849f0f4..63dff01 100644 --- a/src/qml/qml/qqmltypeloader.cpp +++ b/src/qml/qml/qqmltypeloader.cpp @@ -2408,6 +2408,23 @@ void QQmlTypeData::compile() errors << resolver.errors; } + if (errors.isEmpty()) { + // Add to type registry of composites + if (m_compiledData->isCompositeType()) + QQmlEnginePrivate::get(engine)->registerInternalCompositeType(m_compiledData); + else { + const QV4::CompiledData::Object *obj = qmlUnit->objectAt(qmlUnit->indexOfRootObject); + QQmlCompiledData::TypeReference typeRef = m_compiledData->resolvedTypes.value(obj->inheritedTypeNameIndex); + if (typeRef.component) { + m_compiledData->metaTypeId = typeRef.component->metaTypeId; + m_compiledData->listMetaTypeId = typeRef.component->listMetaTypeId; + } else { + m_compiledData->metaTypeId = typeRef.type->typeId(); + m_compiledData->listMetaTypeId = typeRef.type->qListTypeId(); + } + } + } + if (!errors.isEmpty()) { setError(errors); m_compiledData->release(); -- 2.7.4