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. QML module of only qml files do not link to application
Forum Updated to NodeBB v4.3 + New Features

QML module of only qml files do not link to application

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 1 Posters 431 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 a library that define a QML module in Cmake like

    qt6_add_qml_module(MyDesigns
    		URI  MyDesigns
    		VERSION 1.0
    		QML_FILES
    		qml/TextAddress.qml
    		RESOURCE_PREFIX
    		"/esterVtech.com/imports"
    		OUTPUT_TARGETS out_targets_var
    		OUTPUT_DIRECTORY
    		${CMAKE_CURRENT_BINARY_DIR}/MyDesigns
    		)
    

    and then link the module to the main app like

    target_link_libraries(mainapp PRIVATE MyDesigns )
    

    also add the resource prefix to the qml engine like

    engine.addImportPath("qrc:/esterVtech.com/imports");
    

    This return

    qrc:/esterVtech.com/imports/NftMinter/qml/window.qml:7:1: module "MyDesigns" is not installed
    qrc:/esterVtech.com/imports/NftMinter/qml/window.qml: module "MyDesigns" is not installed
    

    By reading qt-add-qml-module, the part it says "It is generally hard to guarantee that a linker preserves the linkage to a library it considers unused"

    It seems that the linker see the "backing library" as unused and do not link it. I tested this by adding sources to the MyDesigns module and use the function defined in the later sources in the main application, and works ok.

    So the linker sees the compiled backing target of qml-files-only as unused by the main app. An I need this backing target because i do not want to use the respective plugin.

    So my question is what is best method to avoid this, like forcing the linking from cmake for every platform.
    From now I will add some foo function to my qml-files-only module and call it in the main app.
    But if someone knows a better simple way I will highly appreciate it.

    MesrineM 1 Reply Last reply
    0
    • MesrineM Mesrine

      Hello everyone,

      I have a library that define a QML module in Cmake like

      qt6_add_qml_module(MyDesigns
      		URI  MyDesigns
      		VERSION 1.0
      		QML_FILES
      		qml/TextAddress.qml
      		RESOURCE_PREFIX
      		"/esterVtech.com/imports"
      		OUTPUT_TARGETS out_targets_var
      		OUTPUT_DIRECTORY
      		${CMAKE_CURRENT_BINARY_DIR}/MyDesigns
      		)
      

      and then link the module to the main app like

      target_link_libraries(mainapp PRIVATE MyDesigns )
      

      also add the resource prefix to the qml engine like

      engine.addImportPath("qrc:/esterVtech.com/imports");
      

      This return

      qrc:/esterVtech.com/imports/NftMinter/qml/window.qml:7:1: module "MyDesigns" is not installed
      qrc:/esterVtech.com/imports/NftMinter/qml/window.qml: module "MyDesigns" is not installed
      

      By reading qt-add-qml-module, the part it says "It is generally hard to guarantee that a linker preserves the linkage to a library it considers unused"

      It seems that the linker see the "backing library" as unused and do not link it. I tested this by adding sources to the MyDesigns module and use the function defined in the later sources in the main application, and works ok.

      So the linker sees the compiled backing target of qml-files-only as unused by the main app. An I need this backing target because i do not want to use the respective plugin.

      So my question is what is best method to avoid this, like forcing the linking from cmake for every platform.
      From now I will add some foo function to my qml-files-only module and call it in the main app.
      But if someone knows a better simple way I will highly appreciate it.

      MesrineM Offline
      MesrineM Offline
      Mesrine
      wrote on last edited by
      #2

      @Mesrine

      This not only happens to backing targets of qml-files-only.
      It happens to any qml module where it symbols are not used on the main application.

      I think this is why Qt uses the plugin target and qmldir.
      Maybe also for tooling you could use the plugin target.

      This is confusing and goes against the reuse and development of QML Modules and types.

      Is there a recommended way of installing the plugin target and qmldir with my backing target using CMake?

      Why not remove the plugin target and use only the backing target,
      so we do not have to take care of the directory structure, QML_IMPORT_PATH ...?

      MesrineM 1 Reply Last reply
      0
      • MesrineM Mesrine

        @Mesrine

        This not only happens to backing targets of qml-files-only.
        It happens to any qml module where it symbols are not used on the main application.

        I think this is why Qt uses the plugin target and qmldir.
        Maybe also for tooling you could use the plugin target.

        This is confusing and goes against the reuse and development of QML Modules and types.

        Is there a recommended way of installing the plugin target and qmldir with my backing target using CMake?

        Why not remove the plugin target and use only the backing target,
        so we do not have to take care of the directory structure, QML_IMPORT_PATH ...?

        MesrineM Offline
        MesrineM Offline
        Mesrine
        wrote on last edited by
        #3

        @Mesrine

        I think the best solution is to install the backing and plugin target.
        Because if the module is STATIC any target that imports that module has to explicitly link to the plugin target.
        Also, I decided to install the plugin dir that is created under the OUTPUT_DIRECTORY so I can later set QML_IMPORT_PATH equal to the folder where all plugin folders are installed. This will load the module at runtime if for some reason the backing target is not linked.

        So it is better to use both targets.

        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