summaryrefslogtreecommitdiffstats
path: root/src/sensors/doc/snippets/sensors/creating.cpp
blob: 09ad955552fae40fa8adca3f5f17c2cd7065a65b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include <QObject>
#include <qaccelerometer.h>
#include <qmagnetometer.h>
#include <qorientationsensor.h>

class MyObject : public QObject
{
    void create();
};

void MyObject::create()
{
//! [Creating a sensor]
// On the heap (deleted when this object is deleted)
QAccelerometer *sensor = new QAccelerometer(this);

// On the stack (deleted when the current scope ends)
QOrientationSensor orient_sensor;
//! [Creating a sensor]

    Q_UNUSED(sensor);
    Q_UNUSED(orient_sensor);

{
//! [2]
QMagnetometer *magnetometer = new QMagnetometer(this);
//! [2]
Q_UNUSED(magnetometer);
}

{
//! [3]
QSensor *magnetometer = new QSensor(QMagnetometer::sensorType, this);
//! [3]
Q_UNUSED(magnetometer);
}

}