Qt Sensors C++ Overview

Explains how to use the Qt Sensors C++ API.

Sensor Types

On a device there can be many types of sensors. Not all of the types that the Qt Sensors API supports may be available. There may also be types available that are not defined in the Qt Sensors API. The types of sensors available on a device is found using the sensorTypes() function.

For a list of built-in sensor types, see the Sensor Classes section below.

Common Conventions

Unless specified otherwise, Qt Sensors uses the Right Hand Cartesian coordinate system .

../_images/sensors-coordinates.jpg

To allow for measurements in all 6 directions, negative values are used.

../_images/sensors-coordinates21.jpg

Where rotation around an axis is used, the rotation shall be expressed as a Right Hand rotation.

../_images/sensors-coordinates31.jpg

In general, sensor data is oriented relative to nativeOrientation , that is to the top of the device when the device is held in its natural orientation (normally when the device logo appears the right side up). If values are to be displayed on the screen, the values may need to be transformed so that they match the user interface orientation. A sensor may define its data as being oriented to the UI. This will be noted in the documentation for the sensor.

../_images/sensors-sides2.jpg

Using a Sensor

The life cycle of a QSensor is typically:

  • Create an instance of QSensor or one of its sub-classes on the stack or heap.

  • Setup as required by the application.

  • Start receiving values.

  • Sensor data is used by the application.

  • Stop receiving values.

Here is an example of creating a sensor on the heap and on the stack.

// On the heap (deleted when this object is deleted)
QAccelerometer *sensor = new QAccelerometer(this);

// On the stack (deleted when the current scope ends)
QOrientationSensor orient_sensor;

Accessing Sensor Data in a Generic Fashion

The preferred way to deal with sensor data is via the Reading Classes . However, sometimes this may not be possible. For example, you may be deploying an application to a device that has a new sensor type but no C++ header describing the reading class is available.

Thanks to Qt’s property system you can still access the sensor data. You need to know 3 pieces of information in order to do this:

  • The sensor type.

  • The property name or index.

  • The property type or a comparable type.

For example, here is an example of how you can access a property of the accelerometer. This code does not require any compile-time links to QAccelerometer or QAccelerometerReading .

// start the sensor
QSensor sensor("QAccelerometer");
sensor.start();

// later
QSensorReading *reading = sensor.reading();
qreal x = reading->property("x").value<qreal>();
qreal y = reading->value(1).value<qreal>();

You can discover all of this information at runtime too. The sensor_explorer example shows you information about available sensors.

Front End, Back End

The Qt Sensors API has a front end, for application developers to use and a back end, where device implementors write code to access their hardware. As an application developer you do not need to access the back end though it may be useful to understand how it works.

Commands from the application are delivered through QSensor and then down to the device plugin. Data comes back through the QSensorReading class.

../_images/sensors-overview.png

More information about the back end can be found in Qt Sensors Backend .

Main Classes

The primary classes that make up the Qt Sensors API.

PySide2.QtSensors.QSensor

The QSensor class represents a single hardware sensor.

PySide2.QtSensors.QSensorFilter

The QSensorFilter class provides an efficient callback facility for asynchronous notifications of sensor changes.

PySide2.QtSensors.QSensorReading

The QSensorReading class holds the readings from the sensor.

Reading Classes

The best way to access sensor data is via one of these classes.

PySide2.QtSensors.QAccelerometerReading

The QAccelerometerReading class reports on linear acceleration along the X, Y and Z axes.

PySide2.QtSensors.QAltimeterReading

The QAltimeterReading class holds readings from the altimeter sensor.

PySide2.QtSensors.QAmbientLightReading

The QAmbientLightReading class represents one reading from the ambient light sensor.

PySide2.QtSensors.QAmbientTemperatureReading

The QAmbientTemperatureReading class holds readings of the ambient temperature.

PySide2.QtSensors.QCompassReading

The QCompassReading class represents one reading from a compass.

PySide2.QtSensors.QDistanceReading

The QDistanceReading class holds distance reading in cm from the proximity sensor.

PySide2.QtSensors.QGyroscopeReading

The QGyroscopeReading class represents one reading from the gyroscope sensor.

PySide2.QtSensors.QHolsterReading

The QHolsterReading class holds readings from the holster sensor.

PySide2.QtSensors.QHumidityReading

The QHumidityReading class holds readings from the humidity sensor.

PySide2.QtSensors.QIRProximityReading

The QIRProximityReading class holds readings from the IR proximity sensor.

PySide2.QtSensors.QLidReading

The QLidReading class holds readings from the Lid sensor.

PySide2.QtSensors.QLightReading

The QLightReading class represents one reading from the light sensor.

PySide2.QtSensors.QMagnetometerReading

The QMagnetometerReading class represents one reading from the magnetometer.

PySide2.QtSensors.QOrientationReading

The QOrientationReading class represents one reading from the orientation sensor.

PySide2.QtSensors.QPressureReading

The QPressureReading class holds readings from the pressure sensor.

PySide2.QtSensors.QProximityReading

The QProximityReading class represents one reading from the proximity sensor.

PySide2.QtSensors.QRotationReading

The QRotationReading class represents one reading from the rotation sensor.

PySide2.QtSensors.QTapReading

The QTapReading class represents one reading from the tap sensor.

PySide2.QtSensors.QTiltReading

The QTiltReading class holds readings from the tilt sensor.

Sensor Classes

These classes provide convenience wrappers that reduce the need for casting. Each of these classes represents a sensor type that the Qt Sensors API knows about. Note that additional types may be made available at run-time. See Sensor Types for more information.

PySide2.QtSensors.QAccelerometer

The QAccelerometer class is a convenience wrapper around QSensor.

PySide2.QtSensors.QAltimeter

The QAltimeter class is a convenience wrapper around QSensor.

PySide2.QtSensors.QAmbientLightSensor

The QAmbientLightSensor class is a convenience wrapper around QSensor.

PySide2.QtSensors.QAmbientTemperatureSensor

The QAmbientTemperatureSensor class is a convenience wrapper around QSensor.

PySide2.QtSensors.QCompass

The QCompass class is a convenience wrapper around QSensor.

PySide2.QtSensors.QDistanceSensor

The QDistanceSensor class is a convenience wrapper around QSensor.

PySide2.QtSensors.QGyroscope

The QGyroscope class is a convenience wrapper around QSensor.

PySide2.QtSensors.QHolsterSensor

The QHolsterSensor class is a convenience wrapper around QSensor.

PySide2.QtSensors.QHumiditySensor

The QHumiditySensor class is a convenience wrapper around QSensor.

PySide2.QtSensors.QIRProximitySensor

The QIRProximitySensor class is a convenience wrapper around QSensor.

PySide2.QtSensors.QLidSensor

The QLidSensor class is a convenience wrapper around QSensor.

PySide2.QtSensors.QLightSensor

The QLightSensor class is a convenience wrapper around QSensor.

PySide2.QtSensors.QMagnetometer

The QMagnetometer class is a convenience wrapper around QSensor.

PySide2.QtSensors.QOrientationSensor

The QOrientationSensor class is a convenience wrapper around QSensor.

PySide2.QtSensors.QPressureSensor

The QPressureSensor class is a convenience wrapper around QSensor.

PySide2.QtSensors.QProximitySensor

The QProximitySensor class is a convenience wrapper around QSensor.

PySide2.QtSensors.QRotationSensor

The QRotationSensor class is a convenience wrapper around QSensor.

PySide2.QtSensors.QTapSensor

The QTapSensor class is a convenience wrapper around QSensor.

PySide2.QtSensors.QTiltSensor

The QTiltSensor class is a convenience wrapper around QSensor.

Filter Classes

As with the sensor classes, these provide convenience wrappers that reduce the need for casting.

PySide2.QtSensors.QAccelerometerFilter

The QAccelerometerFilter class is a convenience wrapper around QSensorFilter.

PySide2.QtSensors.QAltimeterFilter

The QAltimeterFilter class is a convenience wrapper around QSensorFilter.

PySide2.QtSensors.QAmbientLightFilter

The QAmbientLightFilter class is a convenience wrapper around QSensorFilter.

PySide2.QtSensors.QAmbientTemperatureFilter

The QAmbientTemperatureFilter class is a convenience wrapper around QSensorFilter.

PySide2.QtSensors.QCompassFilter

The QCompassFilter class is a convenience wrapper around QSensorFilter.

PySide2.QtSensors.QDistanceFilter

The QDistanceFilter class is a convenience wrapper around QSensorFilter.

PySide2.QtSensors.QGyroscopeFilter

The QGyroscopeFilter class is a convenience wrapper around QSensorFilter.

PySide2.QtSensors.QHolsterFilter

The QHolsterFilter class is a convenience wrapper around QSensorFilter.

PySide2.QtSensors.QHumidityFilter

The QHumidityFilter class is a convenience wrapper around QSensorFilter.

PySide2.QtSensors.QIRProximityFilter

The QIRProximityFilter class is a convenience wrapper around QSensorFilter.

PySide2.QtSensors.QLidFilter

The QLidFilter class is a convenience wrapper around QSensorFilter.

PySide2.QtSensors.QLightFilter

The QLightFilter class is a convenience wrapper around QSensorFilter.

PySide2.QtSensors.QMagnetometerFilter

The QMagnetometerFilter class is a convenience wrapper around QSensorFilter.

PySide2.QtSensors.QOrientationFilter

The QOrientationFilter class is a convenience wrapper around QSensorFilter.

PySide2.QtSensors.QPressureFilter

The QPressureFilter class is a convenience wrapper around QSensorFilter.

PySide2.QtSensors.QProximityFilter

The QProximityFilter class is a convenience wrapper around QSensorFilter.

PySide2.QtSensors.QRotationFilter

The QRotationFilter class is a convenience wrapper around QSensorFilter.

PySide2.QtSensors.QTapFilter

The QTapFilter class is a convenience wrapper around QSensorFilter.

PySide2.QtSensors.QTiltFilter

The QTiltFilter class is a convenience wrapper around QSensorFilter.