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:
First, I had some problems in the CMakeList.txt
file, but I managed to solve them by installing some packages. But now, there are no errors in the CMake file, but the QML file says that the module is not installed.
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
}
}
}
}
}
In addition to the other answer by talamaki, 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.
Note: if you're using Qt 6, you don't need to specify VirtualKeyboard
in your CMakeLists.txt
file — Qt6::QuickControls2
will do it.