Details
-
Bug
-
Resolution: Done
-
P2: Important
-
6.2.5, 6.2, 6.3, 6.4.0 Beta1
-
6.3.0
-
MacOS 12.3.1, Qt Creator 7.0.0
-
-
f5514e682b (qt/qtdeclarative/dev) 58d7d8bd82 (qt/qtdeclarative/6.3) 58d7d8bd82 (qt/tqtc-qtdeclarative/6.3) dc25d739b6 (qt/tqtc-qtdeclarative/6.2)
Description
Relative QML import does not work when deploying and loading QML via an android asset URL. ie. QML files are deployed to the android-build/assets folder and loaded via assets:/ URL.
Cmake:
file(GLOB_RECURSE QmlFolder RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} qml/*.qml)
install(FILES ${QmlFolder} DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/android-build/assets")
main.cpp:
#include <QGuiApplication> #include <QQmlApplicationEngine> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; engine.load("assets:/qml/main.qml"); return app.exec(); }
qml/main.qml:
import QtQuick import "pages" Window { visible: true MainPage { } }
qml/pages/MainPage.qml:
import QtQuick Rectangle { color: "white" anchors.fill: parent Text { text: "Qt 6" } Image { source: "../../images/logo.png" } }
Gives the error message:
file:assets:/qml/main.qml:3:1: import "pages" has no qmldir and no namespace
This worked with Qt 5.
Note: when switching the import statement to:
import "assets:/qml/pages"
It works like expected.
Note how the URL starts with assets:/ here and not file:assets:/. Maybe that is the source of the problem?
The relative lookup of the image placed in assets/images/logo.png also works fine.
The use case here is to directly deploy the QML files in the android assets instead of in QRC resources during development.
Attachments
Issue Links
- relates to
-
QTBUG-104412 FAIL! : tst_AndroidAssets during dependency update
- Closed