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 QSensorPluginInterface::registerSensors() and call QSensorManager::registerBackend() to register available backends. Typically the plugin will also inherit from QSensorBackendFactory and implement QSensorBackendFactory::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 : public QObject, QSensorPluginInterface, public QSensorBackendFactory { Q_OBJECT Q_INTERFACES(QtMobility::QSensorPluginInterface) public: void registerSensors() { QSensorManager::registerBackend(QAccelerometer::type, MyBackend::id, this); } QSensorBackend *createBackend(QSensor *sensor) { if (sensor->identifier() == MyBackend::id) return new MyBackend(sensor); return 0; } };
If you would like to build a backend into a library or application you can use the REGISTER_STATIC_PLUGIN() macro although it may not work in all situations as it uses static initialization.
© 2008-2011 Nokia Corporation and/or its subsidiaries. Nokia, Qt and their respective logos are trademarks of Nokia Corporation in Finland and/or other countries worldwide.
All other trademarks are property of their respective owners. Privacy Policy
Licensees holding valid Qt Commercial licenses may use this document in accordance with the Qt Commercial License Agreement provided with the Software or, alternatively, in accordance with the terms contained in a written agreement between you and Nokia.
Alternatively, this document may be used under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.