Qt Sensors in Qt 6.2

The Qt Sensors module provides access to sensor devices such as accelerometer and gyroscope. The logical architecture separates the concrete sensor types (“accelerometer”) from the platforms providing them (“Android”). This is illustrated by the Figure below:

The original roots of the sensor module in Qt date back to developments for various mobile platforms more than a decade ago. In Qt 6.2 we took the opportunity to revise, crop, and in general solidify the module’s offering to be in a better position to serve the future needs.

The architectural foundation of the module was and remains both generic and solid. In terms of which concrete sensors, platforms, and gestures are supported, many decisions have been made. This blog post will walk you through these changes and the thinking behind them.

Supported Platforms

There are following changes in the platform support in Qt 6.2 compared to Qt 5:

  • Sensors on Windows are supported in the same scope when built with Microsoft Visual Studio Compiler (MSVC).
  • In Qt 5 sensors were supported on Windows RT, which is no longer supported by Qt 6.
  • The “sysfs” -based implementation (an undocumented backend) has been removed as a remnant from the early days of sensors.
  • The ‘sensorfw’ based Linux backend is currently not supported since the “sensorfw” is not ported to Qt 6 yet.
  • The iio-sensor-proxy is currently the only backend supported on Linux, see below for more details
  • The TI Sensor Tag support has been removed. It is a very special “platform” with dependencies on firmware specific aspects. All this requires a lot of effort. We decided to rather spend this effort for the current mainstream platforms

Linux as a sensor platform deserves a special note. The iio-sensor-proxy is able to provide access for some sensors, but it has a D-Bus dependency which might pose a challenge for embedded devices. One possible direction for the future could be a use of the Industrial I/O (IIO) subsystem directly.

Supported Sensor Types

There are also some notable changes in the list of concrete sensor types provided. The sensors that did not have any backing platform support in Qt Sensors were removed. They can be later brought back as needed.  

The code for sensor types which were supported only by ‘sensorfw’ is still present, but has been excluded in the documentation as long as ‘sensorfw’ is not supported on Qt 6. This will make it easier to re-enable ‘sensorfw’ some time in the future.

In summary the main changes:

  • QAltimeter, QDistanceSensor, and QHolsterSensor have been removed
  • QIRProximitySensor, QLidSensor, and QTapSensor have only 'sensorfw' backend and are not listed as supported

While working with Qt Sensors I've really liked the Sensor Explorer example application. It is very handy for many tasks. For example, you can see which sensors are available on your device, and you can activate them and see their values updating:

Gestures with Sensors

In Qt 5, the Qt Sensors module provided a framework for developing gesture detection based on sensor data. An example of such a gesture is the detection of a user shaking a device. One of the major decisions in Qt Sensors for Qt 6.2 was to remove the gesture support as it is known in Qt 5.

There are two main rationales behind this. The first is that gesture algorithms often need tuning for each supported platform in order to provide reliable gesture detection. Sometimes it is even needed for a given device model within that platform. This can quickly result in effort at an unsustainable level, not to mention a possible fragmentation across supported platforms.

The second rationale relates to the uncertainty around the gesture support architecture itself; would there be more natural and perhaps developer-friendly means to provide gesture detection in Qt? After all, many of the gestures can be considered input events. And while some gestures were historically deduced from raw sensor data, some gestures nowadays have their own platform APIs. By removing the support now we allow more free thinking in this regard and I’d very much welcome any thoughts and input here.

I should mention that the code of the gesture framework in Qt 5 is a reasonably thin layer operating on top of sensor data. This code remains available in Qt 5 and can be used for your own development as inspiration.

QML Bindable Properties

Most Qt Sensors QML properties have been added with the relatively new bindable support. This change is not directly visible to the developers as the properties are accessed from QML and not C++, but under the hood this can speed up the execution.

Bugs and Suggestions

At the beginning of the porting effort there were some 80 open bugs or suggestions for the sensors module. It was important to analyze these items as the Qt 6 API break permitted some more wiggling room. As a result about 50% of these items were either fixed or closed. Naturally this work continues but I think it is fair to say that while we have less things at the moment, they are of better quality.


Thank you for reading this far. There are many smaller API changes which you can find in the Qt Sensor’s “Qt 6 changes” documentation. I sincerely believe, and the whole driving intent has been, to provide a more coherent and lean starting point for the future.

I am very happy to hear your thoughts and comments. They are valuable input for going forward.

Blog Topics: