diff options
author | Richard Moe Gustavsen <richard.gustavsen@digia.com> | 2013-08-20 09:02:17 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-13 11:48:08 +0200 |
commit | 31b4461097bd4bd0c128647bab896c2612ef82b0 (patch) | |
tree | 53710dab5d5f89650de71649b84589c212d1856f /tests/auto/tools/moc/tst_moc.cpp | |
parent | 209a5f1e8dc3e2275f225823ad9edfee09ba756c (diff) |
moc: add -M<key=value> to ease static qml plugin linking
A module plugin in qml belongs to a URI/namespace. This
uri is resolved run-time by QtDeclarative by knowing the
path of the qmldir that references the plugin.
For static plugins this becomes a problem, since we lost
the information regarding which plugin belongs to which
qmldir, since a static plugin has no file path.
To avoid pushing the responsibility of clarifying this
onto the application developer, it is better to embed this
information into the meta data of the plugins themselves.
Since this information can be resolved by the
build system, a new option to moc has been added:
-M<key=value>
that will let you add meta tags to the meta data from
the command line to each class that has an IID specified.
For the URI case, we can then e.g do:
-Muri=QtQuick.Controls -Muri=QtQuick.Controls.Private
Change-Id: I81a156660148fc94db6f3cac0473e9e1c8458c58
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Diffstat (limited to 'tests/auto/tools/moc/tst_moc.cpp')
-rw-r--r-- | tests/auto/tools/moc/tst_moc.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp index a6cd85ade5..7fae29e5ca 100644 --- a/tests/auto/tools/moc/tst_moc.cpp +++ b/tests/auto/tools/moc/tst_moc.cpp @@ -531,6 +531,7 @@ private slots: void frameworkSearchPath(); void cstyleEnums(); void defineMacroViaCmdline(); + void specifyMetaTagsFromCmdline(); void invokable(); void singleFunctionKeywordSignalAndSlot(); void templateGtGt(); @@ -1170,6 +1171,37 @@ void tst_Moc::defineMacroViaCmdline() #endif } +// tst_Moc::specifyMetaTagsFromCmdline() +// plugin_metadata.h contains a plugin which we register here. Since we're not building this +// application as a plugin, we need top copy some of the initializer code found in qplugin.h: +extern "C" QObject *qt_plugin_instance(); +extern "C" const char *qt_plugin_query_metadata(); +class StaticPluginInstance{ +public: + StaticPluginInstance() { + QStaticPlugin plugin = { &qt_plugin_instance, &qt_plugin_query_metadata }; + qRegisterStaticPluginFunction(plugin); + } +}; +static StaticPluginInstance staticInstance; + +void tst_Moc::specifyMetaTagsFromCmdline() { + foreach (const QStaticPlugin &plugin, QPluginLoader::staticPlugins()) { + const QString iid = plugin.metaData().value(QLatin1String("IID")).toString(); + if (iid == QLatin1String("test.meta.tags")) { + const QJsonArray metaTagsUriList = plugin.metaData().value("uri").toArray(); + QCOMPARE(metaTagsUriList.size(), 2); + + // The following uri-s are set in the pro file using + // -Muri=com.company.app -Muri=com.company.app.private + QCOMPARE(metaTagsUriList[0].toString(), QLatin1String("com.company.app")); + QCOMPARE(metaTagsUriList[1].toString(), QLatin1String("com.company.app.private")); + return; + } + } + QFAIL("Could not find plugin with IID 'test.meta.tags'"); +} + void tst_Moc::invokable() { { |