diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2021-08-10 12:21:58 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2021-08-17 16:14:53 +0200 |
commit | d0dc91158d0b44d9e1b73c3b0dacdd6699741ad7 (patch) | |
tree | 331cab9fff2169cb76e33ca80d82a175e56e91c0 /src/qml/qml/qqmltypeloader.cpp | |
parent | b4ab58d791167329259f5403e52ce6c85b5f0074 (diff) |
Avoid querying the file system for qmldir files for locked modules
If the user explicitly locks a module using qmlProtectModule, we don't
load any additional qmldir files afterwards. In particular, this means
you can only do that with modules that don't contain qmldir files or
with modules for which the qmldir files have already been loaded in all
engines that need them.
This is in contrast to the "weak" locking we automatically perform when
loading a plugin. When importing the module again after loading a plugin
we do want to re-evaluate the qmldir directives. If the module is
imported from a different engine than before, we also have to search for
the qmldir file again.
Amends commit 914e0300792856ddac9b99b20a8d88dd6f087fa6.
[ChangeLog][QtQml] The pre-5.15 behavior of qmlProtectModule() has
mostly been restored: If you explicitly protect a module, the QML engine
will never look for any qmldir files or plugins for that module again.
This severely limits what you can do with such a module. However, once
all affected engines have loaded the module, protecting it can be a
useful optimization. In contrast to pre-5.15, the qmldir cache for
such modules continues to be re-used even after they are locked.
Therefore, in QML engines that have loaded the module before, you can
expect any "prefer" or "import" directives and any composite types to
still be available after protecting the module.
Fixes: QTBUG-85591
Pick-to: 6.2
Change-Id: Ia4edd860e2ddda5e0c419e1ce9764f10f32ace1f
Reviewed-by: Thorbjørn Lindeijer <bjorn@lindeijer.nl>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@qt.io>
Diffstat (limited to 'src/qml/qml/qqmltypeloader.cpp')
-rw-r--r-- | src/qml/qml/qqmltypeloader.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp index 69331a1cd4..59c9f858f6 100644 --- a/src/qml/qml/qqmltypeloader.cpp +++ b/src/qml/qml/qqmltypeloader.cpp @@ -580,9 +580,14 @@ bool QQmlTypeLoader::Blob::addImport(QQmlTypeLoader::Blob::PendingImportPtr impo scriptImported(blob, import->location, import->qualifier, QString()); } else if (import->type == QV4::CompiledData::Import::ImportLibrary) { + const QQmlImportDatabase::LocalQmldirSearchLocation searchMode = + QQmlMetaType::isStronglyLockedModule(import->uri, import->version) + ? QQmlImportDatabase::QmldirCacheOnly + : QQmlImportDatabase::QmldirFileAndCache; + const QQmlImportDatabase::LocalQmldirResult qmldirResult = importDatabase->locateLocalQmldir( - import->uri, import->version, + import->uri, import->version, searchMode, [&](const QString &qmldirFilePath, const QString &qmldirUrl) { // This is a local library import const QTypeRevision actualVersion = m_importCache.addLibraryImport( |