aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlimport.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-03-01 10:11:18 +0100
committerUlf Hermann <ulf.hermann@qt.io>2021-03-04 23:35:39 +0100
commitce52c245aaccf3183ef4759882e25b51b539195a (patch)
tree5229da9fac5299d95671e551bd2e513942b71d02 /src/qml/qml/qqmlimport.cpp
parent3881f0df3d115ba8e59a5cedea970f3b085aa84a (diff)
Add a "prefer" directive to qmldir
The argument is the path from which further files from the module should be loaded. This allows us to load potentially pre-compiled files from a resource contained in a plugin. The qmldir file has to be stored outside the plugin in order for the QML engine to find it, but the QML files can now be stored inside the plugin. [ChangeLog][QtQml] You can now specify that QML files in a QML module should be loaded from a different place than the directory where the qmldir file is found. To do this, add a "prefer" directive to the qmldir file. The most useful application of this is adding the QML files as resources to a plugin, and using qmlcachegen to pre-compile them. You can then add their path inside the resource file system as "prefer" path in order to make the engine load the pre-compiled files. The plain files should still be installed next to the qmldir file so that they remain visible to tooling. Change-Id: Ib281b39230621b3762432095a47fb499412cbaa6 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlimport.cpp')
-rw-r--r--src/qml/qml/qqmlimport.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp
index 535b6713ba..0016d4bcc4 100644
--- a/src/qml/qml/qqmlimport.cpp
+++ b/src/qml/qml/qqmlimport.cpp
@@ -654,8 +654,18 @@ bool QQmlImportInstance::setQmldirContent(const QString &resolvedUrl,
const QQmlTypeLoaderQmldirContent &qmldir,
QQmlImportNamespace *nameSpace, QList<QQmlError> *errors)
{
- Q_ASSERT(resolvedUrl.endsWith(Slash));
- url = resolvedUrl;
+
+ const QString preferredPath = qmldir.preferredPath();
+ if (preferredPath.isEmpty()) {
+ Q_ASSERT(resolvedUrl.endsWith(Slash));
+ url = resolvedUrl;
+ } else {
+ Q_ASSERT(preferredPath.endsWith(Slash));
+ if (preferredPath.startsWith(u':'))
+ url = QStringLiteral("qrc") + preferredPath;
+ else
+ url = QUrl::fromLocalFile(preferredPath).toString();
+ }
qmlDirComponents = qmldir.components();