センサーの作り方
Qt Sensors モジュールは QML と C++ インタフェースを通じてセンサーハードウェアへのアクセスを提供します。
この API はAndroid、iOS、Windows (MSVC) でサポートされています。
C++ API を使った独自のセンサーの作成
Qt モジュールの C++ API を使用するには、直接または他の依存関係を介して、モジュールライブラリにリンクする必要があります。
センサーの作成
独自のセンサーを作成するには、以下の手順を使用します:
- 独自の MySensor クラスと MySensorReading クラスを作成します。
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; };
- から継承して MySensorBackend を作成します。QSensorBackend
- クラスを継承して、バックエンドをインスタンス化する MySensorBackendFactory ファクトリクラスを作成します。QSensorBackendFactory
- QSensorManager::registerBackend ("MySensorType", "MySensorId", &myfactory) を呼び出してバックエンドファクトリを登録します。
- 新しい MySensor をインスタンス化して使用を開始する。
別のオプションとして、センサーはセンサープラグインを作成することでオンデマンドで使用できるようになります。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.