센서 플러그인 만들기

센서 플러그인이 로드되는 방법

센서 백엔드는 필요에 따라 생성되므로 센서 플러그인이 로드되고 처리하는 센서 백엔드를 등록하라는 요청을 받습니다. 플러그인은 QSensorPluginInterface::registerSensors()를 구현하고 QSensorManager::registerBackend()를 호출하여 사용 가능한 백엔드를 등록해야 합니다. 일반적으로 플러그인은 등록한 백엔드를 인스턴스화하기 위해 QSensorBackendFactory 에서 상속하고 QSensorBackendFactory::createBackend()를 구현하기도 합니다.

가장 간단한 플러그인에는 센서 백엔드가 하나만 있지만 플러그인에 여러 개의 센서 백엔드가 있을 수 없는 이유는 없습니다.

다음은 예제입니다.

class MyPluginClass : public QObject, public QSensorPluginInterface, public QSensorBackendFactory
{
    Q_OBJECT
    //Q_PLUGIN_METADATA(IID "com.qt-project.Qt.QSensorPluginInterface/1.0" FILE "plugin.json")
    Q_INTERFACES(QSensorPluginInterface)
public:
    void registerSensors() override
    {
        QSensorManager::registerBackend(QAccelerometer::sensorType, MyBackend::id, this);
    }

    QSensorBackend *createBackend(QSensor *sensor) override
    {
        if (sensor->identifier() == MyBackend::id)
            return new MyBackend(sensor);
        return 0;
    }
};

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