Overview
Writing a QML application that uses the Legacy Accelerometer QML sensors element requires the following steps:
Import the Legacy Sensors Declarative module.
import QtMobility.sensors 1.2
Add an Accelerometer QML element.
Accelerometer {
id: accel
The accelerometer might run too fast for what we need, so add a timer to read the accelerometer's readings.
Timer {
interval: 500; running: true; repeat: true
property real xdiff;
property real ydiff;
onTriggered: {
xdiff = accel.reading.x - accel.accelX;
ydiff = accel.reading.y - accel.accelY;
if (Math.abs(xdiff) > 0.3) {
accel.accelX = -accel.reading.x
}
if (Math.abs(ydiff) > 0.3) {
accel.accelY = accel.reading.y
}
}
}
Use the 'active' property to start the sensor
active:true
Files:
Images: