diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-12-12 14:05:14 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-12-15 14:59:32 +0100 |
commit | 428cfe2ffd54f8ac03b4acf259de58b7d4fa704f (patch) | |
tree | 348e53ec2651cdb1838ace19c5a31353ef2c51d2 /src/qml/qml | |
parent | 9f7c04985dfe0337cfe8d20ef7605b0a837c199b (diff) |
qqmltypeloader: Allow pluginless qmldir + declarative type registration
Assume an application which uses a QML singleton (so needs qmldir), and
wants to use declarative type registration. This currently breaks
because we find the qmldir, see that there is no plugin to load, and
thus never search for registration functions.
Requiring the creation of a plugin is rather pointless for an
application which doesn't reuse the QML types; so instead enable this
usecase to work. Note that qmldir + imperative registration did always
work, as the imperative registration code did always run.
Change-Id: Iac40020eb97d602d10eb8c4eecac5195ffeabe14
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/qml')
-rw-r--r-- | src/qml/qml/qqmltypeloader.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp index 6c5e7eccb9..e99e6d10ba 100644 --- a/src/qml/qml/qqmltypeloader.cpp +++ b/src/qml/qml/qqmltypeloader.cpp @@ -602,10 +602,10 @@ bool QQmlTypeLoader::Blob::addImport(QQmlTypeLoader::Blob::PendingImportPtr impo if (!loadImportDependencies(import, qmldirFilePath, errors)) return false; + const QQmlTypeLoaderQmldirContent qmldir = typeLoader()->qmldirContent(qmldirFilePath); if (!import->qualifier.isEmpty()) { // Does this library contain any qualified scripts? QUrl libraryUrl(qmldirUrl); - const QQmlTypeLoaderQmldirContent qmldir = typeLoader()->qmldirContent(qmldirFilePath); const auto qmldirScripts = qmldir.scripts(); for (const QQmlDirParser::Script &script : qmldirScripts) { QUrl scriptUrl = libraryUrl.resolved(QUrl(script.fileName)); @@ -615,6 +615,14 @@ bool QQmlTypeLoader::Blob::addImport(QQmlTypeLoader::Blob::PendingImportPtr impo scriptImported(blob, import->location, script.nameSpace, import->qualifier); } } + if (!qmldir.plugins().count()) { + // If the qmldir does not register a plugin, we might still have declaratively + // registered types (if we are dealing with an application instead of a library) + auto module = QQmlMetaType::typeModule(import->uri, import->version); + // If the module already exists, the types must have been already registered + if (!module) + QQmlMetaType::qmlRegisterModuleTypes(import->uri); + } } else if ( // Major version of module already registered: // We believe that the registration is complete. |