Qt Sensors - Accel Bubble
The AccelBubble example demonstrates the Legacy Accelerometer QML type.
Overview
Writing a QML application that uses the Legacy Accelerometer QML sensors type requires the following steps:
Import the Legacy Sensors Declarative module.
import QtSensors 5.0
Add an Accelerometer QML type.
Accelerometer { id: accel dataRate: 100
Use the 'active' property to start the sensor
active:true
Move the bubble according to a factor of the accelerator sensor
onReadingChanged: { var newx = (bubble.x + calcRoll(accel.reading.x, accel.reading.y, accel.reading.z) * .1) var newy = (bubble.y - calcPitch(accel.reading.x, accel.reading.y, accel.reading.z) * .1) if (newx < 0) newx = 0 if (newx > mainPage.width - bubble.width) newx = mainPage.width - bubble.width if (newy < 18) newy = 18 if (newy > mainPage.height - bubble.height) newy = mainPage.height - bubble.height bubble.x = newx bubble.y = newy }
Files: