From 54a1e5a4632d8cce6964b20cb5a6c474daf9a1e2 Mon Sep 17 00:00:00 2001 From: Lincoln Ramsay Date: Fri, 27 Apr 2012 14:04:44 +1000 Subject: Fix the Grue sensor example QtUiTest (and possibly other things) will conspire to ensure our loading hack does not work. Do it the foolproof way instead. Change-Id: I4bb094a43498c2a58da2ed7fc656280ab40d5f06 Reviewed-by: Lorn Potter --- examples/sensors/grue/import/import.pro | 2 +- examples/sensors/grue/import/main.cpp | 47 +++++++++++++++++++++++++-------- 2 files changed, 37 insertions(+), 12 deletions(-) (limited to 'examples') diff --git a/examples/sensors/grue/import/import.pro b/examples/sensors/grue/import/import.pro index 1f74fa3..753e1ef 100644 --- a/examples/sensors/grue/import/import.pro +++ b/examples/sensors/grue/import/import.pro @@ -28,6 +28,6 @@ OTHER_FILES += \ !isEmpty(EXAMPLES_PREFIX) { QMAKE_LFLAGS += -Wl,-rpath,$$EXAMPLES_PREFIX/com.nokia.mt.grue/lib - DEFINES += "BUNDLED_PLUGIN=\\\"$$EXAMPLES_PREFIX/com.nokia.mt.grue/plugins\\\"" + DEFINES += "BUNDLED_PLUGIN=\\\"$$EXAMPLES_PREFIX/com.nokia.mt.grue/plugins/sensors/libqtsensors_grue.so\\\"" } diff --git a/examples/sensors/grue/import/main.cpp b/examples/sensors/grue/import/main.cpp index 2e8583e..6c32703 100644 --- a/examples/sensors/grue/import/main.cpp +++ b/examples/sensors/grue/import/main.cpp @@ -42,12 +42,11 @@ #include #include +#include #ifdef BUNDLED_PLUGIN -#include -#include -#include -#include +#include +#include #endif QT_BEGIN_NAMESPACE @@ -57,13 +56,6 @@ class GrueSensorQmlImport : public QQmlExtensionPlugin Q_OBJECT Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface" FILE "plugin.json") public: -#ifdef BUNDLED_PLUGIN - GrueSensorQmlImport() - { - QCoreApplication::addLibraryPath(QString::fromLocal8Bit(BUNDLED_PLUGIN)); - } -#endif - virtual void registerTypes(const char *uri) { char const * const package = "Grue"; @@ -77,6 +69,39 @@ public: qmlRegisterType (package, major, minor, "GrueSensor"); qmlRegisterUncreatableType(package, major, minor, "GrueSensorReading", QLatin1String("Cannot create GrueSensorReading")); } + +#ifdef BUNDLED_PLUGIN + GrueSensorQmlImport() + { + // For now, this is getting called after Sensors has loaded + // Ensure that a change later does not break this by forcing + // sensors to load now + (void)QSensor::sensorTypes(); + + // Load the bundled sensor plugin + QPluginLoader loader(QString::fromLocal8Bit(BUNDLED_PLUGIN)); + QObject *instance = loader.instance(); + m_changes = qobject_cast(instance); + if (m_changes) { + QSensor *sensor = new QSensor(QByteArray(), this); + connect(sensor, SIGNAL(availableSensorsChanged()), this, SLOT(sensorsChanged())); + m_changes->sensorsChanged(); + } + QSensorPluginInterface *plugin = qobject_cast(instance); + if (plugin) { + plugin->registerSensors(); + } + } + +private slots: + void sensorsChanged() + { + m_changes->sensorsChanged(); + } + +private: + QSensorChangesInterface *m_changes; +#endif }; QT_END_NAMESPACE -- cgit v1.2.1