Problem to find main.qml
-
Hello
I build my first Qt for WebAssembly project. I have many troubles to just get a minimal working example. I can build it but in the browser I just see white with the error messagesQQmlApplicationEngine failed to load component appqt3d.js:11688:12 qrc:/qml/main.qml: No such file or directoryMy project structure looks as follow:
build_wasm.sh clion_wasm_env cmake-build-debug cmake-build-debug-qt-webassembly CMakeLists.txt main.cpp qml resources.qrcand inside the qml folder there is the file main.qml
The root CMakeLists.txt:
cmake_minimum_required(VERSION 3.21) project(qt3d_wasm_project VERSION 0.1 LANGUAGES CXX) message(STATUS "CMAKE_CXX_COMPILER = ${CMAKE_CXX_COMPILER}") message(STATUS "ENV EMSDK = $ENV{EMSDK}") message(STATUS "ENV EM_CONFIG = $ENV{EM_CONFIG}") set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_AUTOUIC ON) find_package(Qt6 REQUIRED COMPONENTS Core Gui Quick Quick3D Qml Quick3DHelpers) qt_add_executable(appqt3d main.cpp resources.qrc ) target_link_options(appqt3d PRIVATE "-sASYNCIFY=1" "-sASYNCIFY_IMPORTS=qt_asyncify_suspend_js,qt_asyncify_resume_js" "-s MODULARIZE=1" "-s EXPORT_NAME=appqt3d_entry" "-s ALLOW_MEMORY_GROWTH=1" "-s INITIAL_MEMORY=64MB" "-s MAXIMUM_MEMORY=4GB" "-s ERROR_ON_UNDEFINED_SYMBOLS=1" "-s FETCH=1" "-s STACK_SIZE=5MB" "-s MAX_WEBGL_VERSION=2" "-s WASM_BIGINT=1" "--profiling-funcs" "-o ${CMAKE_CURRENT_BINARY_DIR}/appqt3d.html" ) target_link_libraries(appqt3d PRIVATE Qt6::Core Qt6::Gui Qt6::Quick Qt6::Quick3D Qt6::Quick3DHelpers )my main.cpp:
#include <QGuiApplication> #include <QQmlApplicationEngine> #include <QUrl> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml"))); if (engine.rootObjects().isEmpty()) return -1; return app.exec(); }and my resources.qrc
<!DOCTYPE RCC> <RCC> <qresource prefix="/qml"> <file>qml/main.qml</file> </qresource> </RCC>Also after reading the other blog entries i still cannot understand why it cannot find my main.qml. Or where the problem lies,
Thank you -
Hello
I build my first Qt for WebAssembly project. I have many troubles to just get a minimal working example. I can build it but in the browser I just see white with the error messagesQQmlApplicationEngine failed to load component appqt3d.js:11688:12 qrc:/qml/main.qml: No such file or directoryMy project structure looks as follow:
build_wasm.sh clion_wasm_env cmake-build-debug cmake-build-debug-qt-webassembly CMakeLists.txt main.cpp qml resources.qrcand inside the qml folder there is the file main.qml
The root CMakeLists.txt:
cmake_minimum_required(VERSION 3.21) project(qt3d_wasm_project VERSION 0.1 LANGUAGES CXX) message(STATUS "CMAKE_CXX_COMPILER = ${CMAKE_CXX_COMPILER}") message(STATUS "ENV EMSDK = $ENV{EMSDK}") message(STATUS "ENV EM_CONFIG = $ENV{EM_CONFIG}") set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) set(CMAKE_AUTOUIC ON) find_package(Qt6 REQUIRED COMPONENTS Core Gui Quick Quick3D Qml Quick3DHelpers) qt_add_executable(appqt3d main.cpp resources.qrc ) target_link_options(appqt3d PRIVATE "-sASYNCIFY=1" "-sASYNCIFY_IMPORTS=qt_asyncify_suspend_js,qt_asyncify_resume_js" "-s MODULARIZE=1" "-s EXPORT_NAME=appqt3d_entry" "-s ALLOW_MEMORY_GROWTH=1" "-s INITIAL_MEMORY=64MB" "-s MAXIMUM_MEMORY=4GB" "-s ERROR_ON_UNDEFINED_SYMBOLS=1" "-s FETCH=1" "-s STACK_SIZE=5MB" "-s MAX_WEBGL_VERSION=2" "-s WASM_BIGINT=1" "--profiling-funcs" "-o ${CMAKE_CURRENT_BINARY_DIR}/appqt3d.html" ) target_link_libraries(appqt3d PRIVATE Qt6::Core Qt6::Gui Qt6::Quick Qt6::Quick3D Qt6::Quick3DHelpers )my main.cpp:
#include <QGuiApplication> #include <QQmlApplicationEngine> #include <QUrl> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml"))); if (engine.rootObjects().isEmpty()) return -1; return app.exec(); }and my resources.qrc
<!DOCTYPE RCC> <RCC> <qresource prefix="/qml"> <file>qml/main.qml</file> </qresource> </RCC>Also after reading the other blog entries i still cannot understand why it cannot find my main.qml. Or where the problem lies,
Thank you@qwendt said in Problem to find main.qml:
<qresource prefix="/qml">
<file>qml/main.qml</file>Your file is in :/qml/qml/main.qml
-
@qwendt said in Problem to find main.qml:
<qresource prefix="/qml">
<file>qml/main.qml</file>Your file is in :/qml/qml/main.qml
@Christian-Ehrlicher thank you, so the working solution is
SOLVED:
<!DOCTYPE RCC> <RCC> <qresource prefix="/"> <file>qml/main.qml</file> </qresource> </RCC>and
#include <QGuiApplication> #include <QQmlApplicationEngine> #include <QUrl> #include <QDirIterator> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:qml/main.qml"))); if (engine.rootObjects().isEmpty()) return -1; return app.exec(); }I am happy!!!