summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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 1f74fa39..753e1ef8 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 2e8583ec..6c327032 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