- Qt 6.7
- Qt Virtual Keyboard
- Building Qt Virtual Keyboard
- Qt Virtual Keyboard | Commercial or GPLv3

# Building Qt Virtual Keyboard

## Overview

This document describes how to build the Qt Virtual Keyboard plugin.

The project is split into the following subprojects:

examples/virtualkeyboard/basic | Qt Virtual Keyboard Demo application
src/components/ | Qt Virtual Keyboard Components QML plugin (QtQuick.VirtualKeyboard.Components)
src/plugin/ | Qt Virtual Keyboard platform input context plugin. This plugin provides the QPlatformInputContext interface and works as a layer between QML input context and platform.
src/plugins/ | A directory containing Qt Virtual Keyboard plugins (QtQuick.VirtualKeyboard.Plugins), which implement complex input methods, such as the HunspellInputMethod. Build time configuration specifies which plugins are built and loaded at runtime.
src/settings/ | Qt Virtual Keyboard Settings QML plugin (QtQuick.VirtualKeyboard.Settings). This plugin provides application-configurable settings for the virtual keyboard.
src/styles/ | Qt Virtual Keyboard Styles QML plugin (QtQuick.VirtualKeyboard.Styles).
src/virtualkeyboard/ | Qt Virtual Keyboard module and QML plugin.

### Configuration Options

The table below contains the top-level options for configuring the virtual keyboard features. These options are passed to the configure tool.

Option | Arguments | Description | Remarks
--- | --- | --- | ---
-vkb-enable <code>[,<code>]*" | Supported language codes or 'all' | Enables the specified language | The specified languages can be explicitly enabled using this option. Each language code has the format language[_country], where: language is a lowercase, two-letter, ISO 639 language code country is an uppercase, two-letter, ISO 3166 country code This option can be used to define the language support as required. The virtual keyboard can support one or more languages at a time. For example, `-vkb-enable de_DE,fi_FI` enables support for the German and Finnish languages. The virtual keyboard automatically includes all supported languages if no other languages are specified.
-vkb-handwriting | [no|example-hwr|myscript-hwr|cerence-hwr] | Enables or disabled handwriting input | This flag enables handwriting input. By default, the engine is automatically activated if it is located in the proper plugins folder even without using of this option. But, in case MyScript and Cerence SDK co-exist, one of [no|myscript-hwr|cerence-hwr] must be configured. The example-hwr option needs to be explicitly activated. This can be done for development and testing purposes.
[-no]-vkb-arrow-keynavigation |  | Enables or disables arrow key navigation for the keyboard | Allows controlling the keyboard using the arrow and return keys. This feature is off by default.
-vkb-style | [standard|retro] | Choose the style of the virtual keyboard | The Qt Virtual Keyboard supports two styles, standard and retro. Both styles will be included in the package, but this option allows you to change the built-in default style.
[-no]-vkb-cangjie |  | Enables or disables the Cangjie input method for Traditional Chinese. | This option enables or disables the Cangjie input method for the Traditional Chinese language. The input method is enabled by default if support for Traditional Chinese is enabled.
[-no]-vkb-zhuyin |  | Enables or disables the Zhuyin input method for Traditional Chinese. | This option enables or disables the Zhuyin input method for the Traditional Chinese language. The input method is enabled by default if support for Traditional Chinese is enabled.
[-no]-vkb-desktop |  | Enables or disables Desktop integration | By default, the desktop integration is enabled when the target environment is X11 or Windows desktop. With this option, the desktop integration can be disabled. Note: For embedded integration, where the InputPanel is instantitated by the application, there is no need to use this option explicitly. The virtual keyboard will not create the desktop input panel if the application creates InputPanel before the focus is set to an input field.
[-no]-vkb-layouts |  | Enables or disables built-in layouts | By default, the virtual keyboard plugin contains the English keyboard layout. By specifiying -no-vkb-layouts, the built-in layout(s) are excluded from the virtual keyboard plugin. Note: In this scenario, the `QT_VIRTUALKEYBOARD_LAYOUT_PATH` environment variable should be set to the file system directory containing the custom keyboard layouts before running the application.
-vkb-hunspell | [no|3rdparty|system] | Choose Hunspell integration | Forces the Hunspell integration method to the specified option. The 3rdparty option selects the local build of the Hunspell source code using project files in the virtual keyboard repo. This option requires that the Hunspell git repository has been cloned into src/plugins/hunspell/3rdparty/hunspell directory. The system option selects the system package via pkg-config. The no option disables the Hunspell plugin.
-vkb-no-bundle-pinyin | n/a | Disables bundling of pinyin resources | This option excludes pinyin resources from the plugin binary. This option may be used to reduce the plugin binary size.
-vkb-no-bundle-tcime | n/a | Disables bundling of tcime resources | This option excludes tcime resources from the plugin binary. This option may be used to reduce the plugin binary size.
-vkb-cerence-sdk | path/to/cerence/sdk | Configures the Cerence SDK location and enables the Cerence Handwriting and XT9 integrations. | The Cerence SDK zip file must be unpacked using the src/plugins/cerence/unpack.py script. By default, the SDK is unpacked to src/plugins/cerence/sdk, where the build scripts can pick it up automatically. However, by using the second parameter to the unpack.py script, it is possible to use different location for the SDK. In that case, the location must be passed to the build script using the -vkb-cerence-sdk command line parameter.
-vkb-cerence-static | handwriting | Enables static linking of the Cerence Handwriting engine. | The Cerence Handwriting engine is linked dynamically by default. Use -vkb-cerence-static to force static linking.
-vkb-bundle-cerence-hwr or -vkb-bundle-cerence | n/a | Enables bundling of Cerence Handwriting resources | This option bundles the Cerence Handwriting resources in the plugin binary.
-vkb-bundle-xt9 or -vkb-bundle-cerence | n/a | Enables bundling of XT9 resources | This option bundles the XT9 resources in the plugin binary.
-vkb-myscript-sdk | path/to/myscript/sdk | Configures the MyScript Text SDK location and enables the MyScript Handwriting integration. | The MyScript Text SDK (zip) which is unpacked to src/plugins/myscript/sdk, can be picked up automatically by the build scripts. However, the SDK can be placed in different location. In that case, the location must be passed to the build script using the `-vkb-myscript-sdk` command line parameter.
-vkb-myscript-arch | [x86|x64|armv7hf|armv7|arm64] | Configures the target CPU architecture | The MyScript Text SDK offers shared (dynamic) libraries for different CPU architectures - [x86|x64|armv7hf|armv7|arm64] for Linux and [x86|x64] for Windows. It can automatically configured. However, a user also can specify the target CPU architecture using the `-vkb-myscript-arch` command line parameter.

### Hunspell Integration

By default, HunspellInputMethod will not be available unless the Hunspell library and development headers are found. For Linux/X11 targets, the Hunspell library can be provided by installing the libhunspell-dev package. Alternatively, the Hunspell git repository can be cloned into the src/plugins/hunspell/3rdparty/hunspell directory. The sources are automatically detected by the qmake and the project will be configured to use the local Hunspell. If Hunspell sources are used, then the dictionary files must also be copied into the src/plugins/hunspell/3rdparty/hunspell/data directory.

An example of how the directory structure should look after setting up the Hunspell sources and dictionary files is listed below:

     3rdparty
     └── hunspell
         ├── data
         │   ├── en_GB.aff
         │   └── en_GB.dic
         ├── hunspell <-- Hunspell git repository
         └── CMakeLists.txt

### Cerence Handwriting Integration

Cerence Handwriting integration supports the Alphabetic and CJK (Chinese Japanese Korean) engines. Both engines are integrated via T9WriteInputMethod. The input method is initialized with one engine at the time. The engine selection happens automatically based on the current input locale.

#### Cerence Handwriting Compatibility

Qt Virtual Keyboard is compatible with Cerence Handwriting v8.7 or later.

#### Cerence Handwriting Build Preparations

The contents of the SDK must unpacked using the unpack.py script located in the cerence directory. This ensures the correct directory structure for CMake to find the content.

     $ cd src/plugins/cerence/
     $ python unpack.py filename.zip

This will unpack the contents to the src/plugins/cerence/sdk directory, where the CMake can pick it up automatically.

Alternatively, you can unpack to any other directory by adding extra parameter to the command line. In this case, the location of the SDK must be passed to the configure script.

     configure ... -vkb-cerence-sdk /path/to/cerence/sdk

#### Layout of the Cerence SDK

The extracted content of the SDK looks like this:

     sdk
     ├───t9write
     │   ├───api
     │   ├───data
     │   │   ├───arabic
     │   │   ├───hebrew
     │   │   └───thai
     │   └───lib
     │       ├───linux
     │       │   ├───arm64
     │       │   │   ├───shared
     │       │   │   │   ├───alphabetic
     │       │   │   │   └───cjk
     │       │   │   └───static
     │       │   │       ├───alphabetic
     │       │   │       └───cjk
     │       │   └───x86_64
     │       │       ├───shared
     │       │       │   ├───alphabetic
     │       │       │   └───cjk
     │       │       └───static
     │       │           ├───alphabetic
     │       │           └───cjk
     │       └───win32
     │           ├───x86
     │           │   ├───shared
     │           │   │   ├───alphabetic
     │           │   │   └───cjk
     │           │   └───static
     │           │       ├───alphabetic
     │           │       └───cjk
     │           └───x86_64
     │               ├───shared
     │               │   ├───alphabetic
     │               │   └───cjk
     │               └───static
     │                   ├───alphabetic
     │                   └───cjk
     └───xt9
         ├───api
         ├───data
         └───lib
             ├───linux
             │   ├───arm64
             │   │   ├───shared
             │   │   └───static
             │   └───x86_64
             │       ├───shared
             │       └───static
             └───win32
                 ├───x86
                 │   ├───shared
                 │   └───static
                 └───x86_64
                     ├───shared
                     └───static

Where the contents of each directory are:

Directory | Description | Remarks
--- | --- | ---
api | This directory should contain all of the API files | The API files usually located in the "api" and "public" directories of the SDK, but sometimes in the "demo" directory. When using both Alphabetic and CJK engines at the same time, any overlapping files can be copied from either SDK.
data | This directory should contain all HWR databases and optionally XT9 databases. | HWR database for the Cerence Handwriting Alphabetic: _databas_le.bin HWR database for the Cerence Handwriting CJK: cjk_HK_std_le.hdb HongKong Chinese cjk_J_std_le.hdb Japanese cjk_K_mkt_le.hdb Korean cjk_S_gb18030_le.hdb Simplified Chinese cjk_T_std_le.hdb Traditional Chinese Language database: File extension is either .ldb or .phd
lib/<target>/<linkage>/<engine-variant> | Directory structure holding supported target builds. | These directories should hold the desired target libraries. If both shared and static libraries are found, shared libraries are preferred.

The Cerence Handwriting and XT9 integration code is automatically activated when the Cerence SDK is detected.

All other extensions should be cleaned from the [qtbase]/plugins/virtualkeyboard directory before building the Cerence extensions to avoid conflicting behavior at runtime. The Cerence extensions do not require any other virtual keyboard plugin to function.

Handwriting databases and language databases for XT9 are installed in the [qtbase]/qtvirtualkeyboard/cerence directory. In addition, there are two other alternatives for locating these files:

- A custom runtime location defined by Environment Variables
- The -vkb-bundle-cerence command line option to embed resources in the plugin binaries

### MyScript Text SDK Integration

MyScript Text is designed for building applications that enable the recognition of handwritten text. MyScript Text supports the recognition of isolated characters, cursive, print and superimposed writing. MyScript superimposed writing is integrated into Qt Virtual Keyboard. It enables the recognition of letters, words or parts of words written one over the other, without any explicit separation between consecutive fragments. It is capable of running on memory and CPU constrained devices.

#### Input handwriting styles of MyScript Text SDK

The end-user can write one word fragment over the other, or one character over the other, as depicted below. Space between two written words are automatically added, so that there is no need for an explicit gesture.

Writing one character over the other
Writing fragments of word over the others

#### Language coverage of MyScript Text SDK

MyScript Superimposed supports 72 languages.

#### MyScript Text SDK Packages Installation

The MyScript delivery team can provide you the packages with various `.zip` archives. To access all the code, tools, and resources needed for building your own handwriting application, extract all the packages in the same destination folder as `src/plugins/myscript/sdk`, where the CMake can pick it up automatically.

Alternatively, you can extract the packages to any other directory. In this case, the location of the SDK must be passed to the configure script.

     configure ... -vkb-myscript-sdk /path/to/myscript/sdk

The file hierarchy should look like below:

     myscript
     └── sdk
         ├─── conf
         ├─── doc
         ├─── edk
         ├─── engine
         │   └─── bin
         │       ├─── lin-arm64
         │       │   └─── *.so
         │       ├─── lin-armv7
         │       │   └─── *.so
         │       ├─── lin-armv7hf
         │       │   └─── *.so
         │       ├─── lin-x64
         │       │   └─── *.so
         │       ├─── lin-x86
         │       │   └─── *.so
         │       ├─── win-x64
         │       │   └─── *.dll
         │       ├─── win-x86
         │       │   └─── *.dll
         │       (etc.)
         ├─── rdk
         ├─── resources
         │   ├─── ar
         │   │   └─── *.res
         │   ├─── en_GB
         │   │   └─── *.res
         │   ├─── ja_JP
         │   │   └─── *.res
         │   ├─── ko_KR
         │   │   └─── *.res
         │   ├─── zh_CN
         │   │   └─── *.res
         │   (etc.)
         ├─── tools
         └─── voim
             ├─── api
             ├─── bin
             │   ├─── lin-arm64
             │   │   └─── *.so
             │   ├─── lin-armv7
             │   │   └─── *.so
             │   ├─── lin-armv7hf
             │   │   └─── *.so
             │   ├─── lin-x64
             │   │   └─── *.so
             │   ├─── lin-x86
             │   │   └─── *.so
             │   ├─── win-x64
             │   │   └─── *.dll
             │   ├─── win-x86
             │   │   └─── *.dll
             │   (etc.)
             └─── conf

The description for the contents of each directory are:

Directory | Description
--- | ---
conf | Contains the language configuration files that the Engine uses to configure language resources.
doc | Contains the HTML documentation files. The file `index.html` displays the main page.
edk | Contains the Engine Development Kit and handwriting programming elements for each supported programming language API, including code samples.
engine | Contains libraries of each engine object, depending on the target platforms it could be SO, A, or DLL.
rdk | Contains the Resource Development Kit, i.e. tools and examples for creating custom resources.
resources | Contains resource files with the /c .res extension. They are binary assets used at run time by the different MyScript technologies to achieve the various recognition tasks.
tools | Contains useful programmer tools including InkTool for ink testing.
voim | Contains libraries of MyScript Text Input Method. It is an extension SDK to the MyScript Text recognition system and designed for building input methods using handwriting recognition easily and quickly.

#### Setting the Certificate of MyScript Text SDK

A valid certificate is mandatory to use the MyScript Text SDK. This is a security measure that uniquely identifies you as a legitimate customer of MyScript technologies. The certificate helps MyScript trace customers' identify and the products that have been purchased.

The certificate is delivered in the `[your_login].vo.zip package`. When you unzip this package, the certificate is automatically put in the appropriate location. This ensure that the certificate is instantly working within the services and code samples that you have been provided with.

#### How to build Qt Virtual Keyboard with MyScript Text SDK

The MyScript integration code is automatically activated when the MyScript Text SDK is detected.

Language resources for MyScript Text SDK are installed in the [qtbase]/qtvirtualkeyboard/myscript directory.

### Static builds

The virtual keyboard can be built and linked statically against the application. This implies that Qt is also built statically (using the -static option in the configure command line).