Importing a C++ types declared using the QML_ELEMENT return module is not installed
-
Hello everyone.
I have created an application using CMake.
The main executable is composed of 2 files "server_main.cpp" and "window_server.qml"
server_main.cpp
#include <QGuiApplication> #include <QQmlApplicationEngine> #ifdef USE_QtQrGen #include "Qrimageprovider.hpp" #endif int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; #ifdef USE_QtQrGen engine.addImageProvider(QLatin1String("qrcodeblack"), new QRImageProvider("black",1)); #endif const QUrl url(u"qrc:plugins/window_server.qml"_qs); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.load(url); return app.exec(); }window_server.qml
import QtQuick.Controls import plugins.interface ApplicationWindow { x:700 y:700 width: 500 height: 800 visible: true StackView { id: stack initialItem: root anchors.fill: parent } Main_view_server { id:root anchors.fill: parent stack:stack } }Here I import a c++ module called 'plugins.interface'. That is defined in a different c++ project that export a library.
The 'CMakeLists.txt' important parts of the main application are :
qt_add_executable(server_main server_main.cpp ) qt_add_qml_module(server_main URI plugins VERSION 1.0 QML_FILES window_server.qml) target_link_libraries(server_main PRIVATE booking_interface)where I add a module and link to other c++ and QML library "booking_interface" that defines the previous 'plugins.interface'' module.
The 'CMakeLists.txt' of the 'booking_interface' target important parts are:
qt6_add_qml_module(booking_interface URI plugins.interface VERSION 1.0 SOURCES src/Hour_model.cpp src/Day_model.cpp include/Day_model.hpp include/Hour_model.hpp QML_FILES qml/Enter_Pin_server.qml qml/Main_view_server.qml qml/window_server.qml OUTPUT_DIRECTORY plugins/interface )When I compile this using gcc_64 there is no problem the application run smoothly.
When compiling with wasm_32 like/path/to/qt-wasm/qtbase/bin/qt-cmake . -DCMAKE_C_COMPILER:FILEPATH=emcc -DCMAKE_CXX_COMPILER:FILEPATH=em++ -DCMAKE_BUILD_TYPE=Release ../ cmake --build .The compilation do not give any errors or warnings and produce the files :
server_main.wasm server_main.html qtloader.js server_main.js server_main.worker.jsthe problem is that when loading the .html file like
emrun server_main.htmlThe developer console of Firefox throws the error
QQmlApplicationEngine failed to load component qrc:plugins/window_server.qml:2:1: module "plugins.interface" is not installedSo it seems QQmlApplicationEngine do not know about the plugins.interface module that was compiled in the 'booking_interface' target and linked to the 'server_main.wasm'.
I will appreciate any help to figure out what is wrong.
Also my understanding is that 'qt6_add_qml_module(booking_interface...' creates an static lib 'libbooking_interface.a' that has inside the 'plugins.interface' module. Where this 'plugins.interface' module has inside the c++ definitions of the class 'Hour_model' ... and the c++ definitions of custom qml types defined in 'qml/Enter_Pin_server.qml'... So if I link any application with this 'libbooking_interface.a' static library and import 'plugins.interface' I will have access to the c++ and QML custom types and I do not need any more the .qml files or the headers .h that I use to create 'libbooking_interface.a'.
If this a correct understanding?