QML module of only qml files do not link to application
-
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. -
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.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 ...? -
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 ...?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 theOUTPUT_DIRECTORY
so I can later setQML_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.