QtMobility Reference Documentation

Sensors QML Plugin

Overview

The QML Sensors Plugin provides an easy to use interface to the Sensors API. It enables us to receive sensor events and to read current values from sensors.

The plugin contains many sensor types and access functions to read values from them. As an example consider the orientation sensor. The orientation example simply displays text on-screen to show the current orientation.

The QML code that reads the value is quite simple. Here we see a QML component orientation declared which is an OrientationSensor element. First the sensor is started by setting the active property to true. The element receives a signal when the reading changes and it is picked up by the onReadingChanged slot. Now the reading property of this element can be used to extract the current orientation so that it can be compared against the defined values of various orientations in the OrientationReading element.

 OrientationSensor {
     id: orientation
     active: true

     onReadingChanged: {

         if (reading.orientation == OrientationReading.FaceUp)
             content.state = "FaceUp";

         // ... more tests for different orientations ...
     }
 }

Other sensors can be treated in a similar manner. For example, the Compass sensor could have almost identical coding

 Compass {
     id: compass
     active: true

     onReadingChanged: {
         compassHeading.text = reading.azimuth;

         // ...
     }
 }

QML Elements

QML Accelerometer Element

The Accelerometer element reports on linear acceleration along the X, Y and Z axes.

QML AmbientLightSensor Element

The AmbientLightSensor element repors on ambient lighting conditions.

QML Compass Element

The Compass element reports on heading using magnetic north as a reference.

QML Gyroscope Element

The Gyroscope element reports on rotational acceleration around the X, Y and Z axes.

QML LightSensor Element

The LightSensor element reports on light levels using LUX.

QML Magnetometer Element

The Magnetometer element reports on magnetic field strength along the Z, Y and Z axes.

QML OrientationSensor Element

The OrientationSensor element reports device orientation.

QML ProximitySensor Element

The ProximitySensor element reports on object proximity.

QML RotationSensor Element

The RotationSensor element reports on device rotation around the X, Y and Z axes.

QML Sensor Element

The Sensor element serves as a base type for sensors.

QML TapSensor Element

The TapSensor element reports tap and double tap events along the X, Y and Z axes.

QML AccelerometerReading Element

The AccelerometerReading element holds the most recent Accelerometer reading.

QML AmbientLightReading Element

The AmbientLightReading element holds the most AmbientLightSensor reading.

QML CompassReading Element

The CompassReading element holds the most recent Compass reading.

QML GyroscopeReading Element

The GyroscopeReading element holds the most recent Gyroscope reading.

QML LightReading Element

The LightReading element holds the most recent LightSensor reading.

QML MagnetometerReading Element

The MagnetometerReading element holds the most recent Magnetometer reading.

QML OrientationReading Element

The OrientationReading element holds the most recent OrientationSensor reading.

QML ProximityReading Element

The ProximityReading element holds the most recent ProximitySensor reading.

QML RotationReading Element

The RotationReading element holds the most recent RotationSensor reading.

QML SensorReading Element

The SensorReading element serves as a base type for sensor readings.

QML TapReading Element

The TapReading element holds the most recent TapSensor reading.

X

Thank you for giving your feedback.

Make sure it is related to this specific page. For more general bugs and requests, please use the Qt Bug Tracker.