Let's move on to a simple example that returns the device's position, accelerometer, gyroscope, ambient light, and magnetometer readings. Here's what our application looks like when running on a Huawei phone:
Note that my Huawei phone does not have a magnetometer, so these readings aren't being updated. Let's see how this works:
- First, we need to ensure that we include the positioning and sensor modules in our .pro file (if we don't, the application will compile but fail to launch):
QT += quick positioning sensors
- Next, we'll move on to the QML itself. This is long but straightforward. First, we add the necessary modules to our project; then, we define the Window object for our program:
import QtQuick 2.12
import QtQuick.Window 2.12
import QtPositioning 5.12
import QtSensors 5.12
Window {
visible: true...