Correct way to deploy QML plugin with support of QDS
-
Hello,
so I'm new to the QML, and after today I have a few questions regarding the modules and deployment. This may read a bit like a odyssey, so go ahead and see the questions highlighted with bold text. I was just thinking that this may be a venture into the mind of the user - and might help to improve docs (or maybe I just missed some very important pieces, but there are SO MANY, haha)
So I have wanted to try an external library QWindowKit (QWK), which also supports QML.
I have built the library and tried to import it in my QML file. Obviously the QDS started complaining that it do not know the module. Sure, it have no means to know where this module resides. So I have checked out how other Qt QML modules looks like and I have noticed there is a
qmldir
and a.qmltypes
file.
So I read a few things in the docs and went ahead and modified the source of the QWK.- To use
QML_ELEMENT
for the type it "exports" to the QML. - And added following code to the CMake that creates the QML module.
qt_add_qml_module(${PROJECT_NAME} URI QWKQuick )
This generated me a
qmldir
andQWKQuick.qmltypes
andQWKQuickplugin.dll
I have tried to extend the importPaths (QML_IMPORTS_PATHS I assume?) of the QDS project with the directory containing the main DLL and the files I have mentioned above.
The error went away, but the battle was not over yet. When I clickedRun
, theApplication output
just printed that it cannot load the plugin.I went ahead and did a little dirty one: I copied the files to the
Qt\Tools\QtDesignStudio\qt6_design_studio_reduced_version\qml\QWKQuick\
. Since theQWKQuick
had a dependency onQWKCore
(which I found out by usingProcessMonitor
), I needed to put theQWKCore
intoQt\Tools\QtDesignStudio\qt6_design_studio_reduced_version\bin\
.Surely there is a an better way to accomplish the same, and make the plugin loadable by QDS? I mean this works, but feels wrong. Almost as wrong as putting the binary dir under
PATH
.
Then there is a second thing I have wanted to ask. So QDS is working now, but I still wanto to be able to use my new QML plugin in my C++/CMake app, right?
So I linkQWindowKit::Quick
to my app and then expect the:qt_generate_deploy_qml_app_script( TARGET ${PROJECT_NAME} OUTPUT_SCRIPT deploy_script NO_UNSUPPORTED_PLATFORM_ERROR )
to do it's magic and copy all the required files to the output dir. Welp doesn't work. Digging through the cmake generated files I found the
set(qml_import_scanner_import_32 "NAME;QWKQuick;TYPE;module;")
. But no idea how to force the qmldeploy to copy it to the output dir. Running the app I get the"QWKQuick" is not installed
message.In my defeat I do the copy step manually via following cmake snippet:
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy -t $<TARGET_FILE_DIR:${PROJECT_NAME}> $<TARGET_RUNTIME_DLLS:${PROJECT_NAME}> COMMAND_EXPAND_LISTS )
And then I call the original
QWK::registerTypes(&engine)
. I have checked the code, and it just registers the types of the QWKQuick "manually/explicitly".My second question is: How do I link external QML module dlls to my app so that the deploy script picks them up, and so that also the
import QWKQuick
works without manual registration from C++ main. Once again - "my" way works, but feels wrong.And lastly, the third question: Is there some troubleshooting guide/process, which describes how one can check how the machinery in the background thinks. So that one can then pin down the issue without shotgunning and digging through generated files?
Thank you for reading this, and looking forward for your insights on the topics :)
- To use