summaryrefslogtreecommitdiffstats
path: root/src/sensors/doc/snippets/sensors
diff options
context:
space:
mode:
Diffstat (limited to 'src/sensors/doc/snippets/sensors')
-rw-r--r--src/sensors/doc/snippets/sensors/CMakeLists.txt32
-rw-r--r--src/sensors/doc/snippets/sensors/creating.cpp44
-rw-r--r--src/sensors/doc/snippets/sensors/main.cpp40
-rw-r--r--src/sensors/doc/snippets/sensors/mybackend.h40
-rw-r--r--src/sensors/doc/snippets/sensors/plugin.cpp42
-rw-r--r--src/sensors/doc/snippets/sensors/sensors.pro10
-rw-r--r--src/sensors/doc/snippets/sensors/start.cpp84
-rw-r--r--src/sensors/doc/snippets/sensors/tutorial.cpp25
8 files changed, 111 insertions, 206 deletions
diff --git a/src/sensors/doc/snippets/sensors/CMakeLists.txt b/src/sensors/doc/snippets/sensors/CMakeLists.txt
new file mode 100644
index 00000000..27480020
--- /dev/null
+++ b/src/sensors/doc/snippets/sensors/CMakeLists.txt
@@ -0,0 +1,32 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+project(sensorsdocsnippet LANGUAGES CXX)
+
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_AUTORCC ON)
+set(CMAKE_AUTOUIC ON)
+
+find_package(Qt6 COMPONENTS Core Sensors)
+
+qt_add_executable(sensorsdocsnippet
+ creating.cpp
+ main.cpp
+ mybackend.h
+ plugin.cpp
+ start.cpp
+)
+
+target_link_libraries(sensorsdocsnippet PUBLIC
+ Qt::Sensors
+)
+
+if (GCC AND UNIX)
+ target_link_libraries(sensorsdocsnippet PUBLIC
+ rdynamic
+ log
+ )
+endif()
diff --git a/src/sensors/doc/snippets/sensors/creating.cpp b/src/sensors/doc/snippets/sensors/creating.cpp
index 4a5ef06d..4c99066f 100644
--- a/src/sensors/doc/snippets/sensors/creating.cpp
+++ b/src/sensors/doc/snippets/sensors/creating.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtSensors module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QObject>
#include <qaccelerometer.h>
@@ -57,7 +21,7 @@ QAccelerometer *sensor = new QAccelerometer(this);
QOrientationSensor orient_sensor;
//! [Creating a sensor]
- Q_UNUSED(sensor)
+ Q_UNUSED(sensor);
Q_UNUSED(orient_sensor);
{
@@ -69,7 +33,7 @@ Q_UNUSED(magnetometer);
{
//! [3]
-QSensor *magnetometer = new QSensor(QMagnetometer::type, this);
+QSensor *magnetometer = new QSensor(QMagnetometer::sensorType, this);
//! [3]
Q_UNUSED(magnetometer);
}
diff --git a/src/sensors/doc/snippets/sensors/main.cpp b/src/sensors/doc/snippets/sensors/main.cpp
index dee1ecb6..fb6724d5 100644
--- a/src/sensors/doc/snippets/sensors/main.cpp
+++ b/src/sensors/doc/snippets/sensors/main.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtSensors module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
int main(int /*argc*/, char ** /*argv*/)
{
diff --git a/src/sensors/doc/snippets/sensors/mybackend.h b/src/sensors/doc/snippets/sensors/mybackend.h
index 59c54069..b964e747 100644
--- a/src/sensors/doc/snippets/sensors/mybackend.h
+++ b/src/sensors/doc/snippets/sensors/mybackend.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtSensors module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#ifndef MYBACKEND_H
#define MYBACKEND_H
diff --git a/src/sensors/doc/snippets/sensors/plugin.cpp b/src/sensors/doc/snippets/sensors/plugin.cpp
index 1eef5966..27f50d72 100644
--- a/src/sensors/doc/snippets/sensors/plugin.cpp
+++ b/src/sensors/doc/snippets/sensors/plugin.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtSensors module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "mybackend.h"
#include <qsensorplugin.h>
@@ -52,7 +16,7 @@ class MyPluginClass : public QObject, public QSensorPluginInterface, public QSen
public:
void registerSensors() override
{
- QSensorManager::registerBackend(QAccelerometer::type, MyBackend::id, this);
+ QSensorManager::registerBackend(QAccelerometer::sensorType, MyBackend::id, this);
}
QSensorBackend *createBackend(QSensor *sensor) override
diff --git a/src/sensors/doc/snippets/sensors/sensors.pro b/src/sensors/doc/snippets/sensors/sensors.pro
deleted file mode 100644
index 91d49772..00000000
--- a/src/sensors/doc/snippets/sensors/sensors.pro
+++ /dev/null
@@ -1,10 +0,0 @@
-TEMPLATE=app
-TARGET=sensorsdocsnippet
-QT = core sensors
-SOURCES+=main.cpp\
- creating.cpp\
- start.cpp\
- plugin.cpp
-HEADERS+=mybackend.h
-!win32:*g++*:LIBS+=-rdynamic
-OTHER_FILES += *.qml
diff --git a/src/sensors/doc/snippets/sensors/start.cpp b/src/sensors/doc/snippets/sensors/start.cpp
index 3ac5b50e..18c87d06 100644
--- a/src/sensors/doc/snippets/sensors/start.cpp
+++ b/src/sensors/doc/snippets/sensors/start.cpp
@@ -1,43 +1,9 @@
-/****************************************************************************
-**
-** Copyright (C) 2017 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtSensors module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2017 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-#include <qsensor.h>
+#include <QtSensors/qsensor.h>
+#include <QtCore/QMetaObject>
+#include <QtCore/QMetaproperty>
void start()
{
@@ -52,6 +18,42 @@ qreal x = reading->property("x").value<qreal>();
qreal y = reading->value(1).value<qreal>();
//! [Starting a sensor]
- Q_UNUSED(x)
- Q_UNUSED(y)
+ Q_UNUSED(x);
+ Q_UNUSED(y);
}
+
+class MyObject : public QObject
+{
+ void findSensors()
+ {
+ //! [Find sensors]
+ QList<QSensor*> mySensorList;
+ for (const QByteArray &type : QSensor::sensorTypes()) {
+ qDebug() << "Found a sensor type:" << type;
+ for (const QByteArray &identifier : QSensor::sensorsForType(type)) {
+ qDebug() << " " << "Found a sensor of that type:" << identifier;
+ QSensor* sensor = new QSensor(type, this);
+ sensor->setIdentifier(identifier);
+ mySensorList.append(sensor);
+ }
+ }
+ //! [Find sensors]
+ //! [Print reading properties]
+ for (QSensor* sensor : mySensorList) {
+ const int firstProperty = QSensorReading::staticMetaObject.propertyOffset();
+ // Connect to backend first in case start() hasn't been called yet
+ if (!sensor->connectToBackend())
+ continue;
+ qDebug() << "Sensor" << sensor->identifier() << "reading properties:";
+ QSensorReading *reading = sensor->reading();
+ if (reading) {
+ const QMetaObject *mo = reading->metaObject();
+ for (int i = firstProperty; i < mo->propertyCount(); ++i) {
+ QByteArray name = mo->property(i).name();
+ qDebug() << " " << name << reading->property(name).toByteArray();
+ }
+ }
+ }
+ //! [Print reading properties]
+ }
+};
diff --git a/src/sensors/doc/snippets/sensors/tutorial.cpp b/src/sensors/doc/snippets/sensors/tutorial.cpp
new file mode 100644
index 00000000..e8714961
--- /dev/null
+++ b/src/sensors/doc/snippets/sensors/tutorial.cpp
@@ -0,0 +1,25 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+//! [MySensor]
+class MyReadingPrivate;
+
+class MyReading : public QSensorReading
+ {
+ Q_OBJECT
+ Q_PROPERTY(qreal myprop READ myprop)
+ DECLARE_READING(MyReading)
+public:
+ qreal myprop() const;
+ void setMyprop(qreal myprop);
+ };
+
+class MySensor : public QSensor
+{
+ Q_OBJECT
+public:
+ explicit MySensor(QObject *parent = 0);
+ MyReading *reading() const;
+ static char const * const sensorType;
+ };
+//! [MySensor]