summaryrefslogtreecommitdiffstats
path: root/src/sensors
diff options
context:
space:
mode:
authorJaishree Vyas <Jaishree.Vyas@qt.io>2023-04-14 15:46:29 +0200
committerJaishree Vyas <Jaishree.Vyas@qt.io>2023-05-24 08:47:28 +0200
commitf54dc7206a6d637ba0eca7f9fcc9e411423d8750 (patch)
treee7b16dde94b8c04d499f06d71f106129e8acca4b /src/sensors
parent240156f91a6b607aae738a6fa2fd3acc7b9e578b (diff)
Tutorial for creating new sensors
Documentation for creating your own sensors Task-number: QTBUG-111251 Change-Id: Ia747995cff99ba34a41ede4125a433fd7952b628 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
Diffstat (limited to 'src/sensors')
-rw-r--r--src/sensors/doc/snippets/sensors/tutorial.cpp25
-rw-r--r--src/sensors/doc/src/qtsensors-tutorial.qdoc36
-rw-r--r--src/sensors/doc/src/qtsensors.qdoc1
3 files changed, 62 insertions, 0 deletions
diff --git a/src/sensors/doc/snippets/sensors/tutorial.cpp b/src/sensors/doc/snippets/sensors/tutorial.cpp
new file mode 100644
index 00000000..c54f46c1
--- /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 LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+//! [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]
diff --git a/src/sensors/doc/src/qtsensors-tutorial.qdoc b/src/sensors/doc/src/qtsensors-tutorial.qdoc
new file mode 100644
index 00000000..147b8504
--- /dev/null
+++ b/src/sensors/doc/src/qtsensors-tutorial.qdoc
@@ -0,0 +1,36 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \page qtsensors-tutorial.html
+ \title How to create your own Sensor
+ \brief Steps for creating your own sensors
+
+ The Qt Sensors module provides access to sensor hardware via QML and C++
+ interfaces.
+
+ The API is supported on \l{Qt for Android}{Android}, \l{Qt for iOS}{iOS}, and
+ \l {Qt for Windows}{Windows (MSVC)}.
+
+ \section1 Creating your own sensor using C++ API
+
+ Using a Qt module's C++ API requires linking against the module library, either
+ directly or through other dependencies.
+ \section2 Creating a sensor
+
+ To create your own sensor you can use the following steps:
+
+ \list
+ \li Create your own MySensor and MySensorReading classes
+ \snippet sensors/tutorial.cpp MySensor
+ \li Create a MySensorBackend by inheriting from QSensorBackend
+ \li Create MySensorBackendFactory factory class for instantiating that
+ backend by inheriting a class QSensorBackendFactory
+ \li Register the backend factory by calling
+ QSensorManager::registerBackend ("MySensorType", "MySensorId", &myfactory)
+ \li Instantiate the new MySensor and start using it
+ \endlist
+
+ As an another option the sensors are put into a \l {Creating a sensor plugin}
+ that you can use on demand.
+*/
diff --git a/src/sensors/doc/src/qtsensors.qdoc b/src/sensors/doc/src/qtsensors.qdoc
index 76235bb6..62959fbd 100644
--- a/src/sensors/doc/src/qtsensors.qdoc
+++ b/src/sensors/doc/src/qtsensors.qdoc
@@ -38,6 +38,7 @@
\li \l {Generic Backend} {Generic Backend}
\li \l {Qt Sensors Backend}
\li \l {Compatibility Map} {Compatibility Map}
+ \li \l {How to create your own Sensor}
\endlist
\section1 Examples