From 24653fc546fe8150ebca1c44c36fe17c36527cc7 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Mon, 12 Oct 2009 14:15:08 +1000 Subject: Test that Component {} is allowed as the root element --- src/declarative/qml/qmlcompiler.cpp | 6 ++++-- tests/auto/declarative/qmllanguage/data/ComponentComposite.qml | 5 +++++ .../declarative/qmllanguage/data/componentCompositeType.qml | 8 ++++++++ tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp | 10 ++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 tests/auto/declarative/qmllanguage/data/ComponentComposite.qml create mode 100644 tests/auto/declarative/qmllanguage/data/componentCompositeType.qml diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index 6d1df6d..023903d 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -672,7 +672,7 @@ bool QmlCompiler::buildObject(Object *obj, const BindingContext &ctxt) obj->className = tr.className; // This object is a "Component" element - if (obj->metatype == &QmlComponent::staticMetaObject) { + if (tr.type && obj->metatype == &QmlComponent::staticMetaObject) { COMPILE_CHECK(buildComponent(obj, ctxt)); return true; } @@ -786,7 +786,9 @@ bool QmlCompiler::buildObject(Object *obj, const BindingContext &ctxt) void QmlCompiler::genObject(QmlParser::Object *obj) { - if (obj->metatype == &QmlComponent::staticMetaObject) { + const QmlCompiledData::TypeReference &tr = + output->types.at(obj->type); + if (tr.type && obj->metatype == &QmlComponent::staticMetaObject) { genComponent(obj); return; } diff --git a/tests/auto/declarative/qmllanguage/data/ComponentComposite.qml b/tests/auto/declarative/qmllanguage/data/ComponentComposite.qml new file mode 100644 index 0000000..f8726ef --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/ComponentComposite.qml @@ -0,0 +1,5 @@ +import Qt 4.6 + +Component { + Object {} +} diff --git a/tests/auto/declarative/qmllanguage/data/componentCompositeType.qml b/tests/auto/declarative/qmllanguage/data/componentCompositeType.qml new file mode 100644 index 0000000..3a1b191 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/componentCompositeType.qml @@ -0,0 +1,8 @@ +import Qt 4.6 + +Object { + property var test + + test: ComponentComposite {} +} + diff --git a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp index 94998c7..a991144 100644 --- a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp +++ b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp @@ -57,6 +57,7 @@ private slots: void valueTypes(); void cppnamespace(); void aliasProperties(); + void componentCompositeType(); void importsBuiltin_data(); void importsBuiltin(); @@ -657,6 +658,15 @@ void tst_qmllanguage::aliasProperties() } } +// Test that the root element in a composite type can be a Component +void tst_qmllanguage::componentCompositeType() +{ + QmlComponent component(&engine, TEST_FILE("componentCompositeType.qml")); + VERIFY_ERRORS(0); + QObject *object = component.create(); + QVERIFY(object != 0); +} + class TestType : public QObject { Q_OBJECT public: -- cgit v0.12