From 9995a2910d8a5f0317fe3adeb54f838b99ab31a8 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Mon, 3 Dec 2012 08:50:11 -0800 Subject: Add a method that allows registration of files to types There is currently no way in C++ to duplicate the functionality of a qmldir file in mapping QML files to versioned types in a module. This functionality would be useful both in cases where a separate qmldir file would be overkill, and for cases where the type mapping should be generated dynamically. Change-Id: I28d7898122c5556fcd7cf3476795bcf4bb288eab Reviewed-by: Christopher Adams --- .../qdeclarativelanguage/data/MyComponentType.qml | 5 +++++ .../qdeclarativelanguage/data/qmlComponentType.qml | 4 ++++ .../qdeclarativelanguage/tst_qdeclarativelanguage.cpp | 13 +++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/MyComponentType.qml create mode 100644 tests/auto/declarative/qdeclarativelanguage/data/qmlComponentType.qml (limited to 'tests') diff --git a/tests/auto/declarative/qdeclarativelanguage/data/MyComponentType.qml b/tests/auto/declarative/qdeclarativelanguage/data/MyComponentType.qml new file mode 100644 index 00000000..9ba0d612 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/MyComponentType.qml @@ -0,0 +1,5 @@ +import QtQuick 1.0 + +Item { + property int test: 11 +} diff --git a/tests/auto/declarative/qdeclarativelanguage/data/qmlComponentType.qml b/tests/auto/declarative/qdeclarativelanguage/data/qmlComponentType.qml new file mode 100644 index 00000000..532bc319 --- /dev/null +++ b/tests/auto/declarative/qdeclarativelanguage/data/qmlComponentType.qml @@ -0,0 +1,4 @@ +import QtQuick 1.0 +import Test 1.0 + +MyComponentType {} diff --git a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp index edbfeeb8..5dbcf456 100644 --- a/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp +++ b/tests/auto/declarative/qdeclarativelanguage/tst_qdeclarativelanguage.cpp @@ -99,6 +99,7 @@ private slots: void assignLiteralToVariant(); void customParserTypes(); void rootAsQmlComponent(); + void qmlComponentType(); void inlineQmlComponents(); void idProperty(); void autoNotifyConnection(); @@ -628,6 +629,16 @@ void tst_qdeclarativelanguage::rootAsQmlComponent() QCOMPARE(object->getChildren()->count(), 2); } +// Tests that types can be specified from a QML only component +void tst_qdeclarativelanguage::qmlComponentType() +{ + QDeclarativeComponent component(&engine, testFileUrl("qmlComponentType.qml")); + VERIFY_ERRORS(0); + QObject *object = qobject_cast(component.create()); + QVERIFY(object != 0); + QCOMPARE(object->property("test"), QVariant(11)); +} + // Tests that components can be specified inline void tst_qdeclarativelanguage::inlineQmlComponents() { @@ -1965,6 +1976,8 @@ void tst_qdeclarativelanguage::initTestCase() { QDeclarativeDataTest::initTestCase(); registerTypes(); + // Registered here because it uses testFileUrl + qmlRegisterType(testFileUrl("MyComponentType.qml"), "Test", 1, 0, "MyComponentType"); // Registering the TestType class in other modules should have no adverse effects qmlRegisterType("com.nokia.TestPre", 1, 0, "Test"); -- cgit v1.2.3