Virtual keyboard does not show up in QWidgets app on RPi 2
-
Hello everybody,
I recently managed to set up a cross-compiling toolchain for Qt 5.7 on a Raspberry Pi 2 with eglfs (following https://wiki.qt.io/RaspberryPi2EGLFS). It works great, but I ran into one issue which I currently can't tackle:
I intend to use the Qt Virtual Keyboard in a QtWidgets based application with a touch screen. I already tried out the Basic example (from examples/virtualkeyboard/basic/) and it's working fine with the Keyboard showing up on tapping the LineEdits.
However, with my example code below the keyboard does not show up if I compile and copy the binary to the Raspberry - although it does when I compile and run it natively on my workstation with the standard toolchain (a self-compiled, shared Qt 5.7 on Linux x64).
There is no error message printed in the terminal.
Any ideas?Here's the code:
// main.cpp #include <QtWidgets> #include <QtGui> int main(int argc, char *argv[]) { qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard")); qputenv("QT_QPA_EGLFS_PHYSICAL_WIDTH", QByteArray("165")); qputenv("QT_QPA_EGLFS_PHYSICAL_HEIGHT", QByteArray("105")); QApplication a(argc, argv); QWidget w; QVBoxLayout layout(&w); layout.addWidget(new QLineEdit()); layout.addWidget(new QLineEdit()); w.show(); return a.exec(); }
and here is my .pro file:
#------------------------------------------------- # # Project created by QtCreator 2017-01-13T21:12:59 # #------------------------------------------------- QT += core gui widgets static { QT += svg QTPLUGIN += qtvirtualkeyboardplugin } TARGET = VirtualKeyboardTest TEMPLATE = app DEFINES += QT_DEPRECATED_WARNINGS SOURCES += main.cpp
-
Hi and welcome to devnet,
You can run your application with the
QT_DEBUG_PLUGINS
environment variable set to 1. This should give you more clues as to why the VK is not shown.Hope it helps
-
Thank you for the advice, @SGaist! I compared the logs of all three cases. In all of them QVirtualKeyboardPlugin is loaded properly, but in my application on the Raspberry there are a number of plugins not being loaded which are loaded on the desktop and the Basic example, including QtVirtualKeyboardStylesPlugin and several QML/QtQuick related plugins. How can I make them load or find out why they don't get loaded?
-
Check that you have everything available on your target.
-
Today I cross-recompiled and reinstalled the whole Qt 5.7.1 toolkit on the target. Then I compiled the virtualkeyboard/basic example again as well as my own application shown above using exactly the same toolchain. Still, my application only loads QVirtualKeyboardPlugin but not the remaining ones. And they are available on the target - virtualkeyboard/basic loads all of them flawlessly. I still have no clue what causes this discrepancy.
-
Did you compare the .pro files ?
Did you check with ldd the plugins that don't load on your target ? -
OK, I finally figured out why it doesn't work as I would like it to. Apparently, in non-desktop environments like EGLFS it is necessary to create an
InputPanel
with QML. So I guess it is impossible to write an application the traditional, QtWidgets-based way if you want to use Qt's virtual keyboard without X11. On the desktop, the only thing you need to do is to setQT_IM_MODULE=qtvirtualkeyboard
and it just works out of the box. -
@mr_max as a workaround you can use a QQuickWidget to contain the input panel.
-
Thank you! Yes, InputPanel was what was needed to make the VirtualKeyboard actually show on embedded (eglfs_kms or wayland). Then it also needs a y and width. And then it is always visible by default, so I guess need to bind visible: active.
The code shown on this page, i.e. without InputPanel, "just worked" on desktop (except the virtual keyboard was massive), but not embedded
https://doc.qt.io/qt-6/qtvirtualkeyboard-basic-example.html
and the "Detailed Description" here didn't really explain why/when to use it
https://doc.qt.io/qt-6/qml-qtquick-virtualkeyboard-inputpanel.html