Details
-
Task
-
Resolution: Unresolved
-
P2: Important
-
6.2.0
-
None
Description
For a qml plugin to be loaded at runtime on Windows, its backing lib .dll file also needs to be found.
For the backing lib to be found, it needs to be either next to the executable or its dir path needs to be in the PATH environment variable.
Currently qt_add_qml_module creates backing libs in the current binary directory of whichever add_subdirectory() call it is in.
The executable could be in a completely different directory, which means plugin loading -> backing lib loading might fail.
We should document that the backing libs should be placed next to the executable. For now this can be achieved by manually setting the output directories of the backing lib with a snippet like the one below, assuming that the executable is in CMAKE_BINARY_DIR.
set(out_dir "${CMAKE_BINARY_DIR}") set_target_properties( Module1 Module2 PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${out_dir}" LIBRARY_OUTPUT_DIRECTORY "${out_dir}" ARCHIVE_OUTPUT_DIRECTORY "${out_dir}" )
In the future, we should consider a new variable that a user can set to a location where all qml backing libs should be placed. That directory can then be added to PATH by the user, instead of adding multiple ones.
To mirror the existing QT_QML_OUTPUT_DIRECTORY we could name it
QT_QML_BACKING_LIB_OUTPUT_DIRECTORY.
Will attach a small project example shortly to demonstrate the issue.
None of the current examples under qtdeclarative/examples showcase the issue because. The only examples that create qml modules not attached to the application, specify the backing lib and plugin target to be the same, so there is no extra .dll that needs to be loaded.