Porting Applications from QtMobility Sensors to Qt Sensors¶
Explain how to port from QtMobility Sensors to Qt Sensors
Overview¶
The initial release of Qt Sensors (5.0) is generally expected to be source compatible with QtMobility Sensors 1.2. This document attempts to explain where things need to be changed in order to port applications to Qt Sensors.
QML¶
In
QtMobility, the C++ classes likeQAccelerometerwere directly used as QML types. In Qt Sensors, there are now separate classes for the QML types, which have no public C++ API.The new QML types in Qt Sensors fix some issues the former QtMobility QML types had, for example:
The reading types now have proper change notifications.
availableDataRatesandoutputRangesof theSensortype are now proper list types.The
identifierandtypeproperties ofSensorcan now be used.The
luxproperty ofLightSensorReadinghas been renamed toilluminance.The
QmlSensorssingleton now allows to query for sensor types.For more information, see the QML API documentation.
C++¶
The C++ API mainly remained the same as in QtMobility.
Includes¶
QtMobility Sensors installed headers into a
QtSensors directory. This is also the directory that Qt Sensors uses. It is therefore expected that includes that worked with QtMobility Sensors should continue to work.For example:
#include <QAccelerometer> #include <qaccelerometer.h> #include <QtSensors/QAccelerometer> #include <QtSensors/qaccelerometer.h>
Macros and Namespace¶
QtMobility Sensors was built in a
QtMobilitynamespace. This was enabled by the use of various macros. Qt Sensors does not normally build into a namespace and the macros from QtMobility no longer exist.
QTM_BEGIN_NAMESPACE
QTM_END_NAMESPACE
QTM_USE_NAMESPACE
QTM_PREPEND_NAMESPACE(x)
Note that Qt can be configured to build into a namespace. If Qt is built in this way then Qt Sensors is also built into the nominated namespace. However, as this is optional, the macros for this are typically defined to do nothing.
QT_BEGIN_NAMESPACE
QT_END_NAMESPACE
QT_USE_NAMESPACE
QT_PREPEND_NAMESPACE(x)
qtimestamp¶
qtimestamp was previously defined as an opaque type equivalent to a quint64. It existed as a class due to an implementation detail.
In Qt Sensors, the API uses quint64 instead of qtimestamp. qtimestamp still exists as a typedef so that applications that refer to qtimestamp can be compiled.
Project Files¶
QtMobility Sensors applications used this in their project files to enable the Sensors API.
CONFIG += mobility MOBILITY += sensorsApplications should remove these lines and instead use the following statement to enable the Qt Sensors API:
QT += sensors
© 2022 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.