Trusted Software Excellence across Desktop and Embedded
Take a glance at the areas of expertise where KDAB excels ranging from swift troubleshooting, ongoing consulting and training to multi-year, large-scale software development projects.
Find out why customers from innovative industries rely on our extensive expertise, including Medical, Biotech, Science, Renewable Energy, Transportation, Mobility, Aviation, Automation, Electronics, Agriculture and Defense.
High-quality Embedded Engineering across the Stack
To successfully develop an embedded device that meets your expectations regarding quality, budget and time to market, all parts of the project need to fit perfectly together.
Learn more about KDAB's expertise in embedded software development.
Where the capabilities of modern mobile devices or web browsers fall short, KDAB engineers help you expertly architect and build high-functioning desktop and workstation applications.
Extensible, Safety-compliant Software for the Medical Sector
Create intelligent, patient-focused medical software and devices and stay ahead with technology that adapts to your needs.
KDAB offers you expertise in developing a broad spectrum of clinical and home-healthcare devices, including but not limited to, internal imaging systems, robotic surgery devices, ventilators and non-invasive monitoring systems.
Building digital dashboards and cockpits with fluid animations and gesture-controlled touchscreens is a big challenge.
In over two decades of developing intricate UI solutions for cars, trucks, tractors, scooters, ships, airplanes and more, the KDAB team has gained market leading expertise in this realm.
Build on Advanced Expertise when creating Modern UIs
KDAB assists you in the creation of user-friendly interfaces designed specifically for industrial process control, manufacturing, and fabrication.
Our specialties encompass the custom design and development of HMIs, enabling product accessibility from embedded systems, remote desktops, and mobile devices on the move.
Legacy software is a growing but often ignored problem across all industries. KDAB helps you elevate your aging code base to meet the dynamic needs of the future.
Whether you want to migrate from an old to a modern GUI toolkit, update to a more recent version, or modernize your code base, you can rely on over 25 years of modernization experience.
KDAB offers a wide range of services to address your software needs including consulting, development, workshops and training tailored to your requirements.
Our expertise spans cross-platform desktop, embedded and 3D application development, using the proven technologies for the job.
When working with KDAB, the first-ever Qt consultancy, you benefit from a deep understanding of Qt internals, that allows us to provide effective solutions, irrespective of the depth or scale of your Qt project.
Qt Services include developing applications, building runtimes, mixing native and web technologies, solving performance issues, and porting problems.
KDAB helps create commercial, scientific or industrial desktop applications from scratch, or update its code or framework to benefit from modern features.
Discover clean, efficient solutions that precisely meet your requirements.
Boost your team's programming skills with in-depth, constantly updated, hands-on training courses delivered by active software engineers who love to teach and share their knowledge.
Our courses cover Modern C++, Qt/QML, Rust, 3D programming, Debugging, Profiling and more.
The collective expertise of KDAB's engineering team is at your disposal to help you choose the software stack for your project or master domain-specific challenges.
Our particular focus is on software technologies you use for cross-platform applications or for embedded devices.
Since 1999, KDAB has been the largest independent Qt consultancy worldwide and today is a Qt Platinum partner. Our experts can help you with any aspect of software development with Qt and QML.
KDAB specializes in Modern C++ development, with a focus on desktop applications, GUI, embedded software, and operating systems.
Our experts are industry-recognized contributors and trainers, leveraging C++'s power and relevance across these domains to deliver high-quality software solutions.
KDAB can guide you incorporating Rust into your project, from as overlapping element to your existing C++ codebase to a complete replacement of your legacy code.
Unique Expertise for Desktop and Embedded Platforms
Whether you are using Linux, Windows, MacOS, Android, iOS or real-time OS, KDAB helps you create performance optimized applications on your preferred platform.
If you are planning to create projects with Slint, a lightweight alternative to standard GUI frameworks especially on low-end hardware, you can rely on the expertise of KDAB being one of the earliest adopters and official service partner of Slint.
KDAB has deep expertise in embedded systems, which coupled with Flutter proficiency, allows us to provide comprehensive support throughout the software development lifecycle.
Our engineers are constantly contributing to the Flutter ecosystem, for example by developing flutter-pi, one of the most used embedders.
KDAB invests significant time in exploring new software technologies to maintain its position as software authority. Benefit from this research and incorporate it eventually into your own project.
Start here to browse infos on the KDAB website(s) and take advantage of useful developer resources like blogs, publications and videos about Qt, C++, Rust, 3D technologies like OpenGL and Vulkan, the KDAB developer tools and more.
The KDAB Youtube channel has become a go-to source for developers looking for high-quality tutorial and information material around software development with Qt/QML, C++, Rust and other technologies.
Click to navigate the all KDAB videos directly on this website.
In over 25 years KDAB has served hundreds of customers from various industries, many of them having become long-term customers who value our unique expertise and dedication.
Learn more about KDAB as a company, understand why we are considered a trusted partner by many and explore project examples in which we have proven to be the right supplier.
The KDAB Group is a globally recognized provider for software consulting, development and training, specializing in embedded devices and complex cross-platform desktop applications.
Read more about the history, the values, the team and the founder of the company.
When working with KDAB you can expect quality software and the desired business outcomes thanks to decades of experience gathered in hundreds of projects of different sizes in various industries.
Have a look at selected examples where KDAB has helped customers to succeed with their projects.
KDAB is committed to developing high-quality and high-performance software, and helping other developers deliver to the same high standards.
We create software with pride to improve your engineering and your business, making your products more resilient and maintainable with better performance.
KDAB has been the first certified Qt consulting and software development company in the world, and continues to deliver quality processes that meet or exceed the highest expectations.
In KDAB we value practical software development experience and skills higher than academic degrees. We strive to ensure equal treatment of all our employees regardless of age, ethnicity, gender, sexual orientation, nationality.
Interested? Read more about working at KDAB and how to apply for a job in software engineering or business administration.
What is an Input Method and what do we need it for?
To answer that question, let's see what Wikipedia says:
"An input method (or input method editor, commonly abbreviated IME) is an operating system component or program that allows any data, such as keyboard strokes or mouse movements, to be received as input. In this way users can enter characters and symbols not found on their input devices."
So an input method allows you for example to input Chinese, Japanese, Korean or Indian characters into a text input field of an application, even though there is only a Latin keyboard attached to the computer.
That is done by analyzing the text, which is typed in as Latin, and e.g. opening a popup menu with a pre-selection of Chinese characters, which are associated with that Latin input. The user can now select one of these Chinese characters, which will then replace the Latin input in the text field.
Since input method support is nowadays an important requirement for UI toolkits, it doesn't come as a surprise that our favorite one (aka Qt) provides it as well. But since Qt is cross-platform, it doesn't support only a single input method, but various ones, depending on the target platform.
In this blog post, we'll have a closer look at how that is implemented, what classes are involved and where it can be extended or adapted.
Input methods in Qt
To get an overview of the input method handling in Qt, let's have a closer look at the involved components first:
QPA plugin: Since version 4.8, Qt contains an abstraction layer (Qt Platform Abstraction), to simplify the porting of the UI parts of Qt to new windowing systems. This layer consists of a set of abstract interface classes (QPlatform*), which are reimplemented for the target windowing system and are bundled as a plugin that can be loaded at runtime. The central interface is QPlatformIntegration, which is instantiated from the plugin by QGuiApplication on startup, and provides access to all the other QPA interfaces.
QPlatformInputContext: The QPlatformInputContext is an abstract interface for the various input method systems that are available on the different windowing systems. For every supported system, there is a sub class of QPlatformInputContext, which implements the communication with the actual input method backend (e.g. QIBusPlatformInputContext for IBus). These subclasses are either available as standalone plugins, which can be loaded at runtime (Qt 5.4 ships two of them, 'ibus' and 'compose'), or are compiled into the QPA plugin (e.g. QQnxInputContext for QNX and QWindowsInputContext for Windows). QPlatformInputContext is part of Qt's private API, so as an application developer, you won't access it directly, instead the global instance of the public class QInputMethod is used. This global instance is returned by QGuiApplication::inputMethod() and it simply forwards the calls to its methods to the global QPlatformInputContext instance. The latter is provided by the loaded QPA plugin (see QPlatformIntegration::inputContext()), which returns one of the above mentioned subclasses.
QGuiApplication: The QGuiApplication inherits QCoreApplication and therefore contains the main event loop of the application, which is responsible for forwarding incoming events from the native windowing system to the appropriated objects in the application. While QCoreApplication only knows about the UI-independent events, the QGuiApplication has knowledge about UI-related states, like which widget has the active keyboard focus, what the current input method is etc.
Text input widgets: The purpose of the text input widgets (e.g. QLineEdit or QTextEdit) is to visualize the keyboard input of the user in a textual representation. Since the key events, which come in from the native windowing system, cannot always be mapped to output characters one-to-one, the text input widgets need support from the input method system to do the conversion.
Follow the stream
While we now know the major players in the game and their roles, in the next step we'll see how they interact with each other. For that, we follow a key stroke on the keyboard throughout the complete system until it shows up as character in a QLineEdit.
The first thing we need in our application is an input widget, which is sensitive to keyboard input. That is easily done by instantiating a QLineEdit. If the user now wants to type in a Chinese character, the first of his actions would be to give this QLineEdit the input focus by either clicking on it with the mouse pointer or navigating to it via the tab chain. As soon as the QLineEdit receives the focus, a private slot in QGuiApplication is called (_q_updateFocusObject), which executes the following steps:
check if the QPlatformIntegration provides a QPlatformInputContext object
if so, check if the object with the input focus wants to use the input method system or handle key events itself
informs the QPlatformInputContext about the new focus object
The first check is easily done, since the QGuiApplication has loaded the QPA plugin itself, so it has access to the QPlatformIntegration instance and can simply call the QPlatformIntegration::inputContext() method to check if a valid QPlatformInputContext object is returned.
The second check is a bit more advanced. To decouple the QGuiApplication from the QWidget interface (and e.g. support also focus handling for QQuickItem), it cannot just call a method on the focus object to query its properties, since that would require QGuiApplication to know their API. Instead QGuiApplication sends a synchronous event (a blocking invocation via QGuiApplication::sendEvent(QEvent*)) to the focus object. Then the focus object fills the event object with the requested information, and when the blocking call returns, the QGuiApplication extracts the information from the event. In short: synchronous event sending is used to decouple QGuiApplication from the public interface of the focus objects.
So what does the event look like and what information can be queried? QInputMethodQueryEvent is the actual event that is used to query the information, and it allows QGuiApplication to query information from the focus object like:
does it accept input method input (Qt::ImEnabled)
the text around the current input area (Qt::ImSurroundingText)
preferred input language (Qt::ImPreferredLanguage) and many, many more (see Qt::InputMethodQuery).
In our case QGuiApplication sends a QInputMethodQueryEvent to QLineEdit and asks for the Qt::ImEnabled flag. QLineEdit responds to that event in the reimplemented QWidget::inputMethodQuery() method, by checking if the Qt::WA_InputMethodEnabled widget attribute is set. This attribute needs to be set by any widget that wants to use the input method system and is set by default on the text input classes (QLineEdit, QTextEdit etc.) in Qt.
The last of the steps executed by _q_updateFocusObject() is to inform the QPlatformInputContext object about the new focus object, so that it can query further information from the focus object if needed later on during the input process. That is simply done by invoking QPlatformInputContext::setFocusObject(QObject *object).
Now that the QLineEdit has the keyboard focus, the user might press a key on the keyboard, which will trigger an input event in the operating system, which will be forwarded to the windowing system and from there call some function in the currently loaded QPA plugin. At that point the QPA plugin would transform the native key event into a QKeyEvent and inject it into the applications event queue by calling QWindowSystemInterface::handleKeyEvent() or QWindowSystemInterface::handleExtendedKeyEvent(). If however an input method system is active, (in that case (QPlatformIntegration::inputContext() returns a valid QPlatformInputContext object), it will send the raw input data to the QPlatformInputContext object instead. How the raw input data are sent to the QPlatformInputContext in that case is not defined by any API, so every QPA implementation is free to choose how to do it. The XCB QPA plugin for example expects the QPlatformInputContext to provide a public slot 'x11FilterEvent', which it invokes with QMetaObject::invokeMethod() and passes the xcb_keysym* data as parameters. That dynamic invocation allows us to use different QPlatformInputContext implementations on XCB systems, without having the XCB QPA plugin know the exact class interface. The QNX QPA plugin on the other hand has the QQnxInputContext compiled in, so it has a pointer to that instance and simply calls a method to forward the raw input data to it.
The QPlatformInputContext subclass has got the raw input data now and can forward them to the actual platform specific input method backend (e.g. send to IBus server via DBus). At that point the input method backend might require additional information to process the current raw input data. Example information could be:
the text around the current input area, to interpret the new input data in a context
the location of the cursor, to open character selection popup menu next to it
To query this information, the QPlatformInputContext sends a synchronous QInputMethodQueryEvent to the current focus object again, exactly as QGuiApplication has done it before. Once it has retrieved this information from the focus object, and forwarded it to the input method backend, the backend will compose a final character (or sequence of characters) that should be set as the new text on the QLineEdit. The composing is either done programatically (by following some writing system specific rules), or the input method system opens a popup menu with a pre-selection of possible characters from which the user selects an appropriated character.
So how does the composed text get back to the QLineEdit? For that, another synchronous event invocation is done. The QPlatformInputContext creates an instance of QInputMethodEvent and calls setCommitString() on it, with the newly composed text as parameter. Afterwards it sends the event to the focus object.
On the focus object, the QLineEdit in our case, the reimplemented method QWidget::inputMethodEvent(QInputMethodEvent*) is invoked. That method will update the current text of the QLineEdit with the composed text, reposition the text cursor and possibly update the current selection.
At that point, the key press event has reached its destination and the user is going to press the next key on the keyboard.
In addition to the commit string, the QPlatformInputContext could also create a QInputMethodEvent with a preedit string and send it to the focus object before composing has started or while composing is in progress. That preedit string is then shown inside the QLineEdit as intermediate result. The visual appearance of that text can be influenced by setting certain attributes on the QInputMethodEvent.
In the next blog post we will learn how to implement an out-of-process virtual keyboard, that uses Qt's input method framework to communicate with Qt-based applications. Stay tuned!
Can you show us an example. I can't find any info about how to implement inputMethodQuery in my custom widget.
9 - Nov - 2015
Tobias Koenig
Hej,
as a reference of how to implement QWidget::inputMethodEvent() and QWidget::inputMethodQuery(), I'd recommend to read the implementation of QLineEdit at http://code.woboq.org/qt5/qtbase/src/widgets/widgets/qlineedit.cpp.html That demonstrate most of the communication that is possible between the widget and the input method system.
18 - Nov - 2015
Markus Hahn
Hi Tobias, thanks for this very detailed article.
With Qt4.x it was very straight forward to raise a virtual keyboard by using a derived class from QInputContext,
and pass it over to QApplication by QApplication::setInputContext( pKeyboardContext );
Now with Qt5.x I'am totaly stucked. This Article explains me why im stucked but not how I can raise my VirtualKeyboard widget, or even the native platform virtual keyboard. Actually how can gain access to QPlatformInputContext ( in my case on windows platform ) .
regards
19 - Nov - 2015
Tobias Koenig
Hej Markus,
with Qt5 the task is split into two parts: 1) let the application raise the virtual keyboard and 2) provide your own virtual keyboard widget. For 1) you simply retrieve the QInputMethod object via QGuiApplication::inputMethod() and then you can call its show()/hide() methods to make the virtual keyboard widget appear/disappear. For 2) you have to implement your own QPlatformInputContext derived class and install it as a plugin (as shown in the example code).
13 - Dec - 2016
Satya srinivas
Can you provide some samples to understand better.
17 - Nov - 2021
Mulfy Crowh
Hi Tobias,
Would you please have an easy example to manage a virtual keyboard with widgets (not QML) with Qt 5?
Something like the Input Panel example Qt 4.8.
Thanks a lot!
Regards,
Michel
10 - Sept - 2024
guanzongjiang
Hello, your article has been very beneficial to me. I have a question that I don't understand. Can Qt develop a system input method? I saw in the article that it mentions lifting a virtual keyboard to complete input, but I don't want to do it within the application. I want to complete input anywhere in the system, such as txt, word, ppt. Can you help me provide some ideas or information
10 - Sept - 2024
Tobias Koenig
Hej,
to develop an system input method, which is available to all UI applications on the system, you'd need to hook into the operating system specific input method frameworks, e.g. like ibus on Linux. These frameworks provide the glue between the applications and the input method implementation (e.g. a virtual keyboard). Of course you can use Qt then to implement the UI of that virtual keyboard, but you have to interact with the native APIs of the frameworks, no wrappers for Qt available.
Tobias Koenig
Senior Software Engineer
Senior software engineer at KDAB, Tobias has actively developed with Qt since 2001 and has been an active KDE contributor during this time. His contributions have been mainly to the KDE PIM project and the KDE libraries, but also to other open source projects. He holds an MSc in Computer Science.
Our hands-on Modern C++ training courses are designed to quickly familiarize newcomers with the language. They also update professional C++ developers on the latest changes in the language and standard library introduced in recent C++ editions.
8 Comments
31 - Oct - 2015
Song Ziming
Can you show us an example. I can't find any info about how to implement
inputMethodQuery
in my custom widget.9 - Nov - 2015
Tobias Koenig
Hej,
as a reference of how to implement QWidget::inputMethodEvent() and QWidget::inputMethodQuery(), I'd recommend to read the implementation of QLineEdit at http://code.woboq.org/qt5/qtbase/src/widgets/widgets/qlineedit.cpp.html That demonstrate most of the communication that is possible between the widget and the input method system.
18 - Nov - 2015
Markus Hahn
Hi Tobias, thanks for this very detailed article. With Qt4.x it was very straight forward to raise a virtual keyboard by using a derived class from QInputContext, and pass it over to QApplication by QApplication::setInputContext( pKeyboardContext );
Now with Qt5.x I'am totaly stucked. This Article explains me why im stucked but not how I can raise my VirtualKeyboard widget, or even the native platform virtual keyboard. Actually how can gain access to QPlatformInputContext ( in my case on windows platform ) . regards
19 - Nov - 2015
Tobias Koenig
Hej Markus,
with Qt5 the task is split into two parts: 1) let the application raise the virtual keyboard and 2) provide your own virtual keyboard widget. For 1) you simply retrieve the QInputMethod object via QGuiApplication::inputMethod() and then you can call its show()/hide() methods to make the virtual keyboard widget appear/disappear. For 2) you have to implement your own QPlatformInputContext derived class and install it as a plugin (as shown in the example code).
13 - Dec - 2016
Satya srinivas
Can you provide some samples to understand better.
17 - Nov - 2021
Mulfy Crowh
Hi Tobias,
Would you please have an easy example to manage a virtual keyboard with widgets (not QML) with Qt 5? Something like the Input Panel example Qt 4.8. Thanks a lot! Regards,
Michel
10 - Sept - 2024
guanzongjiang
Hello, your article has been very beneficial to me. I have a question that I don't understand. Can Qt develop a system input method? I saw in the article that it mentions lifting a virtual keyboard to complete input, but I don't want to do it within the application. I want to complete input anywhere in the system, such as txt, word, ppt. Can you help me provide some ideas or information
10 - Sept - 2024
Tobias Koenig
Hej,
to develop an system input method, which is available to all UI applications on the system, you'd need to hook into the operating system specific input method frameworks, e.g. like ibus on Linux. These frameworks provide the glue between the applications and the input method implementation (e.g. a virtual keyboard). Of course you can use Qt then to implement the UI of that virtual keyboard, but you have to interact with the native APIs of the frameworks, no wrappers for Qt available.