Creating a sensor plugin¶
How a Sensor Plugin is Loaded¶
Since sensor backends are created on demand, the sensor plugin is loaded and asked to register the sensor backends it handles. The plugin should implement registerSensors()
and call registerBackend()
to register available backends. Typically the plugin will also inherit from QSensorBackendFactory
and implement createBackend()
in order to instantiate backends it has registered.
The simplest plugin will have just once sensor backend although there is no reason that multiple sensor backends cannot be in a plugin.
An example follows.
class MyPluginClass(QObject, QSensorPluginInterface, QSensorBackendFactory): Q_OBJECT #Q_PLUGIN_METADATA(IID "com.qt-project.Qt.QSensorPluginInterface/1.0" FILE "plugin.json") Q_INTERFACES(QSensorPluginInterface) # public def registerSensors(): QSensorManager.registerBackend(QAccelerometer.sensorType, MyBackend.id, self) createBackend = QSensorBackend(QSensor sensor) if (sensor.identifier() == MyBackend.id) def MyBackend(sensor): return 0
© 2022 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.