나만의 센서 만드는 방법
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)를 호출하여 백엔드 팩토리를 등록합니다.
- 새 마이센서를 인스턴스화하고 사용을 시작합니다.
또 다른 옵션으로 센서를 필요에 따라 사용할 수 있는 센서 플러그인 만들기에 넣을 수 있습니다.
© 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.