So far, we have learned how we can access the sensors' data through QML scripting. However, the sensors can also be accessed through Qt's various C++ classes. We will walk through some examples of this and demonstrate how we can achieve that.
First, create an empty Qt project (you can continue from the previous example if you wish, though). Instead of writing the code in the .qml file, we will open up main.cpp instead. After that, we will include some headers so that we can access these classes. Remember to add the sensors module to your project file (.pro) if you are creating a new Qt project:
#include <QDebug>
#include <QTimer>
#include <QAccelerometer>
#include <QAmbientLightSensor>
#include <QProximitySensor>
#include <QAccelerometerReading>
#include <QAmbientLightReading>
#include <QProximityReading...