![]() |
Home · All Classes · All Functions · | ![]() |
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 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.
#include "mybackend.h" #include <qsensorplugin.h> #include <qsensormanager.h> class MyPluginClass : public QtMobility::QSensorPluginInterface, public QtMobility::QSensorBackendFactory { Q_OBJECT Q_INTERFACES(QtMobility::QSensorPluginInterface) public: void registerSensors() { QSensorManager::registerBackend(QAccelerationSensor::type, MyBackend::id, this); } QSensorBackend *createBackend(QSensor *sensor) { if (sensor->identifier() == MyBackend::id) return new MyBackend(sensor); return 0; } }; Q_EXPORT_PLUGIN2(libmy_plugin_file_name, MyPluginClass); #include "main.moc"
If you woud 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.
Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies) | Trademarks | Qt Mobility Project 1.0.0 |