diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2021-03-01 10:11:18 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2021-03-04 23:35:39 +0100 |
commit | ce52c245aaccf3183ef4759882e25b51b539195a (patch) | |
tree | 5229da9fac5299d95671e551bd2e513942b71d02 /tests/auto/qml/qqmlimport/tst_qqmlimport.cpp | |
parent | 3881f0df3d115ba8e59a5cedea970f3b085aa84a (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 'tests/auto/qml/qqmlimport/tst_qqmlimport.cpp')
-rw-r--r-- | tests/auto/qml/qqmlimport/tst_qqmlimport.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp index df3d2ba625..4f2b4f6b13 100644 --- a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp +++ b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp @@ -55,6 +55,7 @@ private slots: void importDependenciesPrecedence(); void cleanup(); void envResourceImportPath(); + void preferResourcePath(); }; void tst_QQmlImport::cleanup() @@ -89,6 +90,17 @@ void tst_QQmlImport::envResourceImportPath() QVERIFY((importPaths.contains(path.startsWith(u':') ? QLatin1String("qrc") + path : path))); } +void tst_QQmlImport::preferResourcePath() +{ + QQmlEngine engine; + engine.addImportPath(dataDirectory()); + + QQmlComponent component(&engine, testFileUrl("prefer.qml")); + QVERIFY2(component.isReady(), component.errorString().toUtf8()); + QScopedPointer<QObject> o(component.create()); + QCOMPARE(o->objectName(), "right"); +} + void tst_QQmlImport::testDesignerSupported() { QQuickView *window = new QQuickView(); |