Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for WebAssembly
  4. Importing a C++ types declared using the QML_ELEMENT return module is not installed

Importing a C++ types declared using the QML_ELEMENT return module is not installed

Scheduled Pinned Locked Moved Unsolved Qt for WebAssembly
2 Posts 2 Posters 910 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • MesrineM Offline
    MesrineM Offline
    Mesrine
    wrote on last edited by Mesrine
    #1

    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.js
    

    the problem is that when loading the .html file like

    emrun server_main.html
    

    The developer console of Firefox throws the error

    QQmlApplicationEngine failed to load component
    qrc:plugins/window_server.qml:2:1: module "plugins.interface" is not installed
    

    So 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?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SWMCODER
      wrote on last edited by
      #2

      I think I might have a similar problem. Any update on your original issue?

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved