Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. runtime error: module is not installed when using qt_add_qml_module()
Forum Updated to NodeBB v4.3 + New Features

runtime error: module is not installed when using qt_add_qml_module()

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 528 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.
  • T Offline
    T Offline
    timjquetee
    wrote on 2 May 2024, 00:32 last edited by
    #1

    I'm following various examples and documentation trying to learn how to use qt_add_qml_module() to create a simple module mymodule using cmake and have my windows QML application import and use that module.

    I get the following error message at run-time:

    qrc:/main.qml:4:1: module "modules.mymodule" is not installed
    

    I think I am missing some fundamental understanding or step.
    The file modules/mymodule/CMakeLists.txt is:

    cmake_minimum_required(VERSION 3.16)
    qt_add_qml_module(mymodule
        URI modules.mymodule
        VERSION 1.0
        QML_FILES MyRect.qml
        SHARED)
    

    The file modules/mymodule/MyRect.qml is:

    import QtQuick
    import QtQuick.Controls.Basic
    import QtQuick.Layouts
    
    Item {
        id: root
        implicitWidth: 50
        implicitHeight: 50
        Rectangle {
            color: "blue"
            anchors.fill: parent
        }
    }
    

    The main.qml file imports this module and tries to display a MyRect:

    import QtQuick
    import modules.mymodule
    
    ApplicationWindow {
        id: root
        visible: true
    
        width: 1000
        height: 800
    
        MyRect {
    
        }
       ...
    

    The CMakeLists.txt for the main application includes the following:

    qt_add_executable(mytestapp main.cpp)
    set_target_properties(mytestapp PROPERTIES WIN32_EXECUTABLE ON)
    target_link_libraries(mytestapp PRIVATE Qt6::Core Qt6::Gui Qt6::Qml Qt6::Quick)
    qt_add_qml_module(mytestapp URI main VERSION 1.0 QML_FILES main.qml NO_RESOURCE_TARGET_PATH NO_PLUGIN IMPORTS modules.mymodules)
    
    find_program(WINDEPLOYQT_EXE windeployqt.exe)
    add_custom_command(
        TARGET mytestapp POST_BUILD
        COMMAND ${WINDEPLOYQT_EXE} --no-translations $<TARGET_FILE:mytestapp > --qmldir ${CMAKE_CURRENT_SOURCE_DIR}
        COMMENT "Running windeployqt for target mytestapp "
    )
    

    And the main.cpp is:

    int main(int argc, char **argv)
    {
        QGuiApplication app(argc, argv);
        app.setApplicationName(QFileInfo(app.applicationFilePath()).baseName());
        QQmlApplicationEngine engine;
        engine.load(QUrl("qrc:/main.qml"));
        return app.exec(); 
    }
    

    I have been able to work-around the error if I change mymodule to be built as a STATIC library instead of SHARED, and also explicitly add mymodule to the target_link_libraries() of the main applicaiton. I don't understand why using STATIC works, but using SHARED doesn't. When using a SHARED library for mymodule, I can see the .dll file mymodule.dll being copied to the application build directory, but the error says "module "modules.mymodule" is not installed". What does 'installed' mean in this context?

    1 Reply Last reply
    0

    1/1

    2 May 2024, 00:32

    • Login

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