このページでは

独自のセンサーの作成方法

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 クラスから継承して MySensorBackend を作成しますQSensorBackend
  • そのバックエンドをインスタンス化するための MySensorBackendFactory ファクトリクラスを作成します。これには、あるクラスを継承しますQSensorBackendFactory
  • QSensorManager::registerBackend ("MySensorType", "MySensorId", &myfactory) を呼び出して、バックエンドファクトリを登録します
  • 新しい MySensor をインスタンス化し、使用を開始します

別の方法として、センサーをオンデマンドで使用できるセンサープラグインを作成します。

© 2026 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.