How to fix VirtualKeyboard not found in Qt Creator QML?

1.1k Views Asked by At

I am developing a project using Qt QML and C++. I want to use Qt Virtual Keyboard in it. I installed the Component and imported it. My Qt configuration:

  1. Qt 6.4.2
  2. Qt Creator 9.0.2
  3. Cmake 4.3

Firstly, I had some problems in the CMakeList.txt file but I managed to solve them by installing some packages. But now their are no errors in Cmake file but I QML file it says that module is not installed.

Qt Creator Desig

Here is my CMake file content:

cmake_minimum_required(VERSION 3.16)

project(VultureOS VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOMOC ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Qt6 6.2 COMPONENTS Quick REQUIRED)
find_package(Qt6 COMPONENTS Core Gui Quick VirtualKeyboard REQUIRED)

qt_add_executable(appVultureOS
    main.cpp
)

qt_add_qml_module(appVultureOS
    URI VultureOS
    VERSION 1.0
    QML_FILES main.qml 
)

set_target_properties(appVultureOS PROPERTIES
    MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

target_link_libraries(appVultureOS
    PRIVATE Qt6::Quick)
target_link_libraries(
    appVultureOS PRIVATE Qt6::Core Qt6::Gui Qt6::Quick Qt6::VirtualKeyboard)

install(TARGETS appVultureOS
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

And this is my QML file:

import QtQuick 2.15 import QtQuick.VirtualKeyboard

Window {
    id: window
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")

    InputPanel {
        id: inputPanel
        z: 99
        x: 0
        y: window.height
        width: window.width

        states: State {
            name: "visible"
            when: inputPanel.active
            PropertyChanges {
                target: inputPanel
                y: window.height - inputPanel.height
            }
        }
        transitions: Transition {
            from: ""
            to: "visible"
            reversible: true
            ParallelAnimation {
                NumberAnimation {
                    properties: "y"
                    duration: 250
                    easing.type: Easing.InOutQuad
                }
            }
        }
    }
}

Please help me out! Thanks in advance

2

There are 2 best solutions below

0
mzimmers On BEST ANSWER

In addition to what @talamaki said, you probably also need an input field (like TextField) if you want your keyboard to activate automatically. At this point, you'll discover that you need some positioning in order to make everything appear nicely in your window.

BTW: if you're using Qt 6, you don't need to specify VirtualKeyboard in your CMakeLists.txt file -- Qt6::QuickControls2 will do it.

1
talamaki On

You don't show your main.cpp but I guess you don't load the plugin. That's explained in the Qt virtual keyboard deployment guide, e.g.

int main(int argc, char *argv[])
{
    qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));

    QGuiApplication app(argc, argv);