Search code examples
c++qtqt5qt5.12qt5.15

Qt virtualkeyboard assertion error in 5.15.2 vs 5.12.3


I recently updated my Qt version from 5.12.3 to 5.15.2. I rebuilt an application that uses a qt virtualkeyboard in QML using InputPanel {}. The virtual keyboard is defined in main as qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));. Everything works in release mode but when I run in debug mode I get the following application output from qt creator:

Program: C:\Qt\5.15.2\msvc2019_64\bin\Qt5Cored.dll
Module: 5.15.2
File: qvirtualkeyboardinputcontext_p.cpp
Line: 221

ASSERT: "!this->inputPanel" in file qvirtualkeyboardinputcontext_p.cpp, line 221

I inspected the source file on Github for 5.15.2 and the line number points to method void QVirtualKeyboardInputContextPrivate::registerInputPanel(QObject *inputPanel) with Q_ASSERT(!this->inputPanel);. I wanted to compare this method with Github for 5.12.3 but it looks like this method was added after 5.12.3 hence why I didn't see the error before.

Now, my understanding is that Q_ASSERT(bool) will call qFatal() when the flag is false. If inputPanel is of type QObject* should the Q_ASSERT be Q_ASSERT(this->inputPanel)? The Q_ASSERT should only trigger when the pointer is a nullptr. Or maybe I'm just confused?


Solution

  • There was already an existing bug report on Qt's bug tracker. Previously I only searched by virtualkeyboard and not InputPanel. The bug report is here. BTW, it looks like this is only an issue in debug mode and a workaround is to click the ignore button several times to continue in debug mode.

    Edit: Qt responded that this assert check is to make sure that there is only 1 InputPanel component in the whole application. So, I am not sure how InputPanel is suppose to work when we have multiple dynamic views in a MVVM architecture design where each view has it's own self contained InputPanel.

    Edit2: Updating per my last edit comment. I put the InputPanel at the main qml file that controls the StackView and the views that are dynamically loaded are able to use the same InputPanel.