summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorLincoln Ramsay <lincoln.ramsay@nokia.com>2012-04-27 14:04:44 +1000
committerQt by Nokia <qt-info@nokia.com>2012-04-27 07:12:42 +0200
commit54a1e5a4632d8cce6964b20cb5a6c474daf9a1e2 (patch)
tree9dffe765f89d28e272bd34462a830b1b7d92db6c /examples
parent09fe2e61de1dd9f195ac0d7232bc4db0c381d1b1 (diff)
downloadqtsensors-54a1e5a4632d8cce6964b20cb5a6c474daf9a1e2.tar.gz
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 <lorn.potter@nokia.com>
Diffstat (limited to 'examples')
-rw-r--r--examples/sensors/grue/import/import.pro2
-rw-r--r--examples/sensors/grue/import/main.cpp47
2 files changed, 37 insertions, 12 deletions
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 <QtQml/qqml.h>
#include <gruesensor.h>
+#include <QDebug>
#ifdef BUNDLED_PLUGIN
-#include <QFile>
-#include <QCoreApplication>
-#include <QQmlEngine>
-#include <QStringList>
+#include <QPluginLoader>
+#include <QSensorPluginInterface>
#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 <GrueSensor >(package, major, minor, "GrueSensor");
qmlRegisterUncreatableType<GrueSensorReading>(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<QSensorChangesInterface*>(instance);
+ if (m_changes) {
+ QSensor *sensor = new QSensor(QByteArray(), this);
+ connect(sensor, SIGNAL(availableSensorsChanged()), this, SLOT(sensorsChanged()));
+ m_changes->sensorsChanged();
+ }
+ QSensorPluginInterface *plugin = qobject_cast<QSensorPluginInterface*>(instance);
+ if (plugin) {
+ plugin->registerSensors();
+ }
+ }
+
+private slots:
+ void sensorsChanged()
+ {
+ m_changes->sensorsChanged();
+ }
+
+private:
+ QSensorChangesInterface *m_changes;
+#endif
};
QT_END_NAMESPACE