Reputation: 8569
How do I activate the Qt5 virtual keyboard for my application? And more importantly, what files are needed for the Qt virtual keyboard to appear in my deployed application?
Im asking this Q&A style since it's taken me surprisingly long to put together all bits and pieces. Maybe someone else will benefit from this.
Upvotes: 2
Views: 1697
Reputation: 8569
The documentation for Qt Virtual Keyboard is actually not that bad. However putting everything in place for a deployed application is still challenging for QtWidgets/C++
projects. I've tested following suggestions with Qt 5.10 and Windows 10:
Install the virtual keyboard. In Windows this is possible with the Qt installer, by selecting the option "Qt Virtual Keyboard" under the respective Qt version.
(Tell me what's needed for other platforms - I'll add this information)
Enable the environment variable, i.e. loading the plugin can be implemented in the main.cpp
(before instantiating any QApplication
):
qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
This will enable the virtual keyboard for any input field.
What files are needed for the deployment of an application? The virtual keyboard needs its own plugin.dll, and it depends on the modules Qt5Network, QtQml, QtQuick, QtSvg
. So the directory structure would have to have at least these files:
platforminputcontexts/qtvirtualkeyboardplugin.dll
YOURBIN.exe
Qt5Network.dll
Qt5Qml.dll
Qt5Quick.dll
Qt5Svg.dll
Edit: The plugin will dynamically load some more plugins, also using plugin description files, so deploy these, too (find them in the qml
sub-dir of the qt installation directory):
Qt/labs/folderlistmodel/qmldir
Qt/labs/folderlistmodel/qmlfolderlistmodelplugin.dll
QtQuick/Layouts/qmldir
QtQuick/Layouts/qquicklayoutsplugin.dll
QtQuick/VirtualKeyboard/Styles/qmldir
QtQuick/VirtualKeyboard/Styles/qtvirtualkeyboardstylesplugin.dll
QtQuick/Window.2/qmldir
QtQuick/Window.2/windowplugin.dll
QtQuick.2/qmldir
QtQuick.2/qtquick2plugin.dll
Apart from these files, the standard Dlls are needed and possibly other plugins, DLLs. This all depends on your configuration and also if you use MSVC or MinGW:
iconengines/...dll
imageformats/...dll
platform/...dll
Qt5Gui.dll
Qt5Widget.dll
Qt5Core.dll
libwinpthread-1.dll
libEGL.dll
libGLESv2.dll
libstdc++-6.dll
libgcc_s_dw2-1.dll
Note: The qt windows deployment tool is a nice and handy tool. However, it did not, by default, copy all files required for the virtual keyboard.
EDIT - Note2: The qt windows deployment tool can copy almost all required files. It won't copy the virtual keyboard style DLL (Qt 5.10, Mingw). Also it does copy a lot of unnecessary files, if only virtual keyboard is required:
windeployqt.exe --compiler-runtime --qmldir c:\Qt\5.10.0\mingw53_32\qml
--quick --qml --release --force PATH_TO_BINARY
Then manually create the directories/copy the respective DLL + qmldir
from and to:
QtQuick/VirtualKeyboard/Styles
Upvotes: 4