Qt Sensors - Explorer QML example

Sensor Explorer in QML

The Sensor Explorer example demonstrates how to read the meta-data of available sensors.

This example is divided into two parts:

  • A C++ plug-in that provides QML alternatives for QSensorExplorer, QPropertyInfo and the QSensorItem classes.
  • A QML Application that uses the QML alternatives to read the sensors meta-data and present it.

This is a pure QML application that can be run from Qt Creator or directly using the qmlscene binary. You should install the other C++ plug-in before trying to run this example, otherwise it will not find its dependencies.

qmlscene main.qml

To write a QML application that will use the Explorer QML type you need to do the following steps:

Import the Explorer 1.0 declarative plugin:

import Explorer 1.0

Create a SensorExplorer QML item:

    SensorExplorer {
        id: explorer
    }

You can retrieve a list of all available sensors using the SensorExplorer:

        listmodel: explorer.availableSensors

To retrieve the properties of a SensorItem use:

                propertyList.listmodel = sensorList.selectedItem.properties;

Changing a property value can be done like:

                explorer.selectedSensorItem.changePropertyValue(propertyList.selectedItem, textfield.text);

Starting and stopping a sensor can be done like:

                if (text === "Start") {
                    explorer.selectedSensorItem.start = true;
                    text = "Stop";
                }
                else {
                    explorer.selectedSensorItem.start = false;
                    text = "Start";
                }

Files: