Windows - qt_add_qml_module failed to load the plugin
-
Hi All
Unable to load the plugin created using qt_add_qml_module
CMake on Windows , Qt 6.6.3, Mingw_64.
Creating the library & adding new qml module using
qt_add_qml_module(..)This creates the plugin.
However when I import in QML, it is unable to load the plugin.
I tried to load the plugin using QPluginLoader. This also fails.Same CMake configuration works on Linux without any change.
Anyone facing similar issue ?
-
Here is the answer - qt_add_qml_module builds plugin & one shared library. Both have to be in path. I tried to add the path using the addLibraryPath. Adding the path using addLibraryPath did not help. Finally I modified the path environment variable. It started working.
- May be bug with addLibraryPath. Need to file a bug on this.
- add the path of the shared library & plugin to environment variable. It works.
-
D dheerendra has marked this topic as solved on
-
D dheerendra referenced this topic on
-
Here is the answer - qt_add_qml_module builds plugin & one shared library. Both have to be in path. I tried to add the path using the addLibraryPath. Adding the path using addLibraryPath did not help. Finally I modified the path environment variable. It started working.
- May be bug with addLibraryPath. Need to file a bug on this.
- add the path of the shared library & plugin to environment variable. It works.
@dheerendra Thanks for sharing your solution! There is no bug, however.
qt_add_qml_module() generates 2 library targets by default: One "backing target" like
MyModule.dll(which contains your actual QML code) and one "plugin target" likeMyModuleplugin.dll(which contains plugin interface)-
Your backing target must be put in one of Windows' standard DLL search paths (see https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#standard-search-order-for-unpackaged-apps ) -- usually, you would put it next to your *.exe (or you could also put it in one of your PATH folders).
-
Your plugin target must be put in a "module folder". This "module folder"...
- ...must have the same name as your QML module
- ...must contain your plugin target AND the module definition files (qmldir file + *.qmltypes file)
- ...must be found inside of your QML engine's import paths. See https://doc.qt.io/qt-6/qqmlengine.html#importPathList
-
@JKSH True. Agree with you. Expectation was that after adding the library path it should work. This is where my confusion.
-
@JKSH True. Agree with you. Expectation was that after adding the library path it should work. This is where my confusion.
@dheerendra can you show some demo source? I don't konw how to write qml plugin and use the component in app.qml, thank you .