[SOLVED]Deploying a Qt Quick 2 plugin with a static build
-
We have a Qt Quick 2 plugin used by our Windows application for file system access directly in QML; it's a standard and simple plugin made using the Qt Quick 2 Extension template. When running using the standard Qt build of our application, it works fine, but when making a static build for deployment, it doesn't load - debug output is:
qrc:///elements/BinaryFile.qml: Type FileAccess unavailable qrc:///FileAccess.qml:5:1: module "com.monomix.qmlcomponents" plugin "FileIO" not found
The contents of FileAccess.qml are:
pragma Singleton import QtQuick 2.3 import com.monomix.qmlcomponents 1.0 QtObject { property FileIO fileIO: FileIO { id: fileIoInstance } }
and the FileIO.dll plugin itself is stored in com/monomix/qmlcomponents, along with the required plugins.qmltypes and qmldir file, which contains:
module com.monomix.qmlcomponents plugin FileIO
At runtime the application recognises the module, so it wouldn't seem to be an issue with paths, but for some reason the plugin isn't found. Any ideas?
-
After a lot of digging and experimentation, I finally got this working; as usual, the devil is in the (largely undocumented) details. There are still some open questions as to why it works, but it works. Things to note:
-
The QML extension plugin must be built using the same compiler and static-linked Qt that you're compiling your application with
-
In the .pro file for you plugin, you need to define QMAKE_MOC_OPTIONS:
uri = com.yourcompany.qmlcomponents QMAKE_MOC_OPTIONS += -Muri=com.yourcompany.qmlcomponents
-
If you're definining a plugin which contains a singleton class, use qmlRegisterSingletonType in your MyPlugin::registerTypes() function rather than qmlRegisterType
-
For linking your application statically, you need to define classname in your plugin's qmldir file. See http://doc.qt.io/qt-5/qtqml-modules-qmldir.html
-
When building your application, you should add your custom plugin to QmlImports.qml (see https://forum.qt.io/topic/53072/qml-with-static-build/2)
-
As with the QtQuick DLLS described in the link in 5., you need to distribute the dynamically-linked build of your plugin with the application, located in a defined plugin path.
Source code for the plugin project can be found here, for anyone who's interested: https://gist.github.com/anonymous/97d6b1fa78b13439ed35
-
-
Hi,
You could contribute an update to Qt's documentation with these information or open a bug report (if none already exists) on the bug report system to improve the documentation in that regard
-
The same you would do for code. You can start by reading the Gerrit Introduction