Creación de un plugin de sensor
Cómo se Carga un Plugin de Sensor
Como los backends de los sensores son creados bajo demanda, el plugin del sensor es cargado y se le pide que registre los backends de los sensores que maneja. El plugin debería implementar QSensorPluginInterface::registerSensors() y llamar a QSensorManager::registerBackend() para registrar los backends disponibles. Típicamente el plugin también heredará de QSensorBackendFactory e implementará QSensorBackendFactory::createBackend() para instanciar los backends que ha registrado.
El plugin más simple tendrá sólo un sensor backend aunque no hay razón para que múltiples sensores backends no puedan estar en un plugin.
A continuación se muestra un ejemplo.
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; } };
© 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.