summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLorn Potter <lorn.potter@nokia.com>2011-11-11 10:46:31 +1000
committerQt by Nokia <qt-info@nokia.com>2011-11-14 06:54:31 +0100
commitd95c5fee483816558246586c4621d96c84b224c0 (patch)
tree6d458feddc453baf26ef85130f8447e8d0d2a6ab
parent1f20d5ef3e27981e2af2c6533656694ea3335678 (diff)
remove qmobilitypluginsearch and use the QFactoryLoader instead.
Change-Id: Ifdd2031d309a5ac4cbeedc5d7cdb6ba9cbb845c3 Reviewed-by: Lincoln Ramsay <lincoln.ramsay@nokia.com> Sanity-Review: Lincoln Ramsay <lincoln.ramsay@nokia.com>
-rw-r--r--doc/src/snippets/sensorgestures/myplugin.h7
-rw-r--r--doc/src/snippets/sensors/plugin.cpp5
-rw-r--r--examples/sensors/grue/plugin/main.cpp3
-rw-r--r--examples/sensors/qmlsensorgestures/plugin/qcountergestureplugin.h5
-rw-r--r--src/plugins/sensorgestures/shake/qshakesensorgestureplugin.h5
-rw-r--r--src/plugins/sensors/dummy/main.cpp3
-rw-r--r--src/plugins/sensors/generic/main.cpp3
-rw-r--r--src/plugins/sensors/simulator/main.cpp5
-rw-r--r--src/sensors/gestures/qsensorgesturemanagerprivate.cpp22
-rw-r--r--src/sensors/gestures/qsensorgestureplugininterface.cpp11
-rw-r--r--src/sensors/gestures/qsensorgestureplugininterface.h15
-rw-r--r--src/sensors/qmobilitypluginsearch.h173
-rw-r--r--src/sensors/qsensormanager.cpp9
-rw-r--r--src/sensors/qsensorplugin.h9
-rw-r--r--src/sensors/qsensorpluginloader.cpp27
-rw-r--r--src/sensors/qsensorpluginloader_p.h1
-rw-r--r--tests/auto/qsensor/test_sensorplugin.cpp7
-rw-r--r--tests/auto/qsensorgestures/plugins/test/qtestsensorgestureplugin_p.h5
-rw-r--r--tests/auto/qsensorgestures/plugins/test1/qtestsensorgestureplugindup.h3
-rw-r--r--tests/auto/sensors2qmlapi/qbackends.h3
-rw-r--r--tests/auto/sensors2qmlapi/qtemplategestureplugin.h4
21 files changed, 94 insertions, 231 deletions
diff --git a/doc/src/snippets/sensorgestures/myplugin.h b/doc/src/snippets/sensorgestures/myplugin.h
index 91020f0b..294cca48 100644
--- a/doc/src/snippets/sensorgestures/myplugin.h
+++ b/doc/src/snippets/sensorgestures/myplugin.h
@@ -45,7 +45,7 @@
#include <qsensorgestureplugininterface.h>
#include <qsensorgesturerecognizer.h>
-class MySensorGestureRecognizer : public QSensorGestureRecognizer
+class MySensorGestureRecognizer : public QSensorGestureRecognizer
{
Q_OBJECT
public:
@@ -65,10 +65,11 @@ Q_SIGNALS:
void mySignal();
};
-class MySensorGesturePlugin : public QObject, QSensorGesturePluginInterface
+class MySensorGesturePlugin : public QObject, public QSensorGesturePluginInterface
{
Q_OBJECT
- Q_INTERFACES(QSensorGesturePluginInterface)
+ Q_INTERFACES(QSensorGesturePluginInterface:QFactoryInterface)
+
explicit MySensorGesturePlugin();
~MySensorGesturePlugin();
diff --git a/doc/src/snippets/sensors/plugin.cpp b/doc/src/snippets/sensors/plugin.cpp
index 2567ab74..2c80ed6f 100644
--- a/doc/src/snippets/sensors/plugin.cpp
+++ b/doc/src/snippets/sensors/plugin.cpp
@@ -45,10 +45,10 @@
const char *MyBackend::id = "mybackend";
//! [Plugin]
-class MyPluginClass : public QObject, QSensorPluginInterface, public QSensorBackendFactory
+class MyPluginClass : public QObject, public QSensorPluginInterface, public QSensorBackendFactory
{
Q_OBJECT
- Q_INTERFACES(QSensorPluginInterface)
+ Q_INTERFACES(QSensorPluginInterface:QFactoryInterface)
public:
void registerSensors()
{
@@ -61,6 +61,7 @@ public:
return new MyBackend(sensor);
return 0;
}
+ QStringList keys() const { return QStringList() << "myplugin";}
};
//! [Plugin]
diff --git a/examples/sensors/grue/plugin/main.cpp b/examples/sensors/grue/plugin/main.cpp
index bdafa287..50333f2d 100644
--- a/examples/sensors/grue/plugin/main.cpp
+++ b/examples/sensors/grue/plugin/main.cpp
@@ -48,7 +48,7 @@
class GrueSensorPlugin : public QObject, public QSensorPluginInterface, public QSensorChangesInterface, public QSensorBackendFactory
{
Q_OBJECT
- Q_INTERFACES(QSensorPluginInterface QSensorChangesInterface)
+ Q_INTERFACES(QSensorPluginInterface:QFactoryInterface QSensorChangesInterface)
public:
void registerSensors()
{
@@ -74,6 +74,7 @@ public:
return 0;
}
+ QStringList keys() const { return QStringList() << "grue";}
};
Q_EXPORT_PLUGIN2(libsensors_grueplugin, GrueSensorPlugin);
diff --git a/examples/sensors/qmlsensorgestures/plugin/qcountergestureplugin.h b/examples/sensors/qmlsensorgestures/plugin/qcountergestureplugin.h
index 33075f43..842afeee 100644
--- a/examples/sensors/qmlsensorgestures/plugin/qcountergestureplugin.h
+++ b/examples/sensors/qmlsensorgestures/plugin/qcountergestureplugin.h
@@ -46,10 +46,11 @@
#include <qsensorgestureplugininterface.h>
-class QCounterGesturePlugin : public QObject, QSensorGesturePluginInterface
+class QCounterGesturePlugin : public QObject, public QSensorGesturePluginInterface
{
Q_OBJECT
- Q_INTERFACES(QSensorGesturePluginInterface)
+ Q_INTERFACES(QSensorGesturePluginInterface:QFactoryInterface)
+
public:
explicit QCounterGesturePlugin();
~QCounterGesturePlugin();
diff --git a/src/plugins/sensorgestures/shake/qshakesensorgestureplugin.h b/src/plugins/sensorgestures/shake/qshakesensorgestureplugin.h
index d11b9ee9..068656f2 100644
--- a/src/plugins/sensorgestures/shake/qshakesensorgestureplugin.h
+++ b/src/plugins/sensorgestures/shake/qshakesensorgestureplugin.h
@@ -47,10 +47,11 @@
#include <qsensorgestureplugininterface.h>
-class QShakeSensorGesturePlugin : public QObject, QSensorGesturePluginInterface
+class QShakeSensorGesturePlugin : public QObject, public QSensorGesturePluginInterface
{
Q_OBJECT
- Q_INTERFACES(QSensorGesturePluginInterface)
+ Q_INTERFACES(QSensorGesturePluginInterface:QFactoryInterface)
+
public:
explicit QShakeSensorGesturePlugin();
~QShakeSensorGesturePlugin();
diff --git a/src/plugins/sensors/dummy/main.cpp b/src/plugins/sensors/dummy/main.cpp
index f7cf85f6..9b9bc237 100644
--- a/src/plugins/sensors/dummy/main.cpp
+++ b/src/plugins/sensors/dummy/main.cpp
@@ -50,7 +50,7 @@
class dummySensorPlugin : public QObject, public QSensorPluginInterface, public QSensorBackendFactory
{
Q_OBJECT
- Q_INTERFACES(QSensorPluginInterface)
+ Q_INTERFACES(QSensorPluginInterface:QFactoryInterface)
public:
void registerSensors()
{
@@ -71,6 +71,7 @@ public:
return 0;
}
+ QStringList keys() const { return QStringList() << "dummy";}
};
Q_EXPORT_PLUGIN2(qtsensors_dummy, dummySensorPlugin)
diff --git a/src/plugins/sensors/generic/main.cpp b/src/plugins/sensors/generic/main.cpp
index 7714ce02..d72abdd3 100644
--- a/src/plugins/sensors/generic/main.cpp
+++ b/src/plugins/sensors/generic/main.cpp
@@ -51,7 +51,7 @@
class genericSensorPlugin : public QObject, public QSensorPluginInterface, public QSensorChangesInterface, public QSensorBackendFactory
{
Q_OBJECT
- Q_INTERFACES(QSensorPluginInterface QSensorChangesInterface)
+ Q_INTERFACES(QSensorPluginInterface:QFactoryInterface QSensorChangesInterface)
public:
void registerSensors()
{
@@ -92,6 +92,7 @@ public:
return 0;
}
+ QStringList keys() const { return QStringList() << "generic";}
};
Q_EXPORT_PLUGIN2(qtsensors_generic, genericSensorPlugin)
diff --git a/src/plugins/sensors/simulator/main.cpp b/src/plugins/sensors/simulator/main.cpp
index 641f7a69..c470d12a 100644
--- a/src/plugins/sensors/simulator/main.cpp
+++ b/src/plugins/sensors/simulator/main.cpp
@@ -49,10 +49,10 @@
#include <QSensorBackend>
#include <QSensorManager>
-class SimulatorSensorPlugin : public QObject, public QSensorPluginInterface, public QSensorBackendFactory
+class SimulatorSensorPlugin : public QSensorPluginInterface,public QObject, public QSensorBackendFactory
{
Q_OBJECT
- Q_INTERFACES(QSensorPluginInterface)
+ Q_INTERFACES(QSensorPluginInterface:QFactoryInterface)
public:
void registerSensors()
{
@@ -92,6 +92,7 @@ public:
return 0;
}
+ QStringList keys() const { return QStringList() << "simulator";}
};
Q_EXPORT_PLUGIN2(libsensors_simulator, SimulatorSensorPlugin)
diff --git a/src/sensors/gestures/qsensorgesturemanagerprivate.cpp b/src/sensors/gestures/qsensorgesturemanagerprivate.cpp
index 2f85561b..292248b4 100644
--- a/src/sensors/gestures/qsensorgesturemanagerprivate.cpp
+++ b/src/sensors/gestures/qsensorgesturemanagerprivate.cpp
@@ -42,13 +42,19 @@
#include <QDir>
#include <QLibraryInfo>
+#include <QtCore/private/qfactoryloader_p.h>
+
#include "qsensorgesturerecognizer.h"
#include "qsensorgesturemanagerprivate_p.h"
#include "qsensorgestureplugininterface.h"
-#include "qmobilitypluginsearch.h"
QT_BEGIN_NAMESPACE
+#ifndef QT_NO_LIBRARY
+Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
+ (QSensorGestureFactoryInterface_iid, QLatin1String("/sensorgestures")))
+#endif
+
QSensorGestureManagerPrivate::QSensorGestureManagerPrivate(QObject *parent) :
QObject(parent)
{
@@ -58,7 +64,6 @@ QSensorGestureManagerPrivate::QSensorGestureManagerPrivate(QObject *parent) :
QSensorGestureManagerPrivate::~QSensorGestureManagerPrivate()
{
qDeleteAll(registeredSensorGestures);
- qDeleteAll(plugins);
}
@@ -87,17 +92,10 @@ QSensorGestureManagerPrivate::~QSensorGestureManagerPrivate()
*/
void QSensorGestureManagerPrivate::loadPlugins()
{
- // Qt-style static plugins
- Q_FOREACH (QObject *plugin, QPluginLoader::staticInstances()) {
- initPlugin(plugin);
- }
-
- QStringList gestureplugins = mobilityPlugins(QLatin1String("sensorgestures"));
- for (int i = 0; i < gestureplugins.count(); i++) {
-
- QPluginLoader *loader = new QPluginLoader(gestureplugins.at(i), this);
+ QFactoryLoader *l = loader();
+ foreach (const QString &key, l->keys()) {
- QObject *plugin = loader->instance();
+ QObject *plugin = l->instance(key);
if (plugin) {
initPlugin(plugin);
}
diff --git a/src/sensors/gestures/qsensorgestureplugininterface.cpp b/src/sensors/gestures/qsensorgestureplugininterface.cpp
index 8a68fbcf..95ceca3b 100644
--- a/src/sensors/gestures/qsensorgestureplugininterface.cpp
+++ b/src/sensors/gestures/qsensorgestureplugininterface.cpp
@@ -80,4 +80,15 @@
Returns this plugins name.
*/
+QT_BEGIN_NAMESPACE
+QSensorGesturePluginInterface::QSensorGesturePluginInterface()
+{
+}
+
+QSensorGesturePluginInterface::~QSensorGesturePluginInterface()
+{
+
+}
+
+QT_END_NAMESPACE
diff --git a/src/sensors/gestures/qsensorgestureplugininterface.h b/src/sensors/gestures/qsensorgestureplugininterface.h
index 93185b77..8128f0e4 100644
--- a/src/sensors/gestures/qsensorgestureplugininterface.h
+++ b/src/sensors/gestures/qsensorgestureplugininterface.h
@@ -44,24 +44,29 @@
#include <QObject>
#include <QtGlobal>
-
+#include <QtCore/qplugin.h>
+#include <QtCore/qfactoryinterface.h>
#include "qsensorgesture.h"
#include "qsensorgesturerecognizer.h"
QT_BEGIN_NAMESPACE
class QSensorGestureRecognizer;
-class Q_SENSORS_EXPORT QSensorGesturePluginInterface
+#define QSensorGestureFactoryInterface_iid "com.Nokia.QSensorGesturePluginInterface"
+
+
+class Q_SENSORS_EXPORT QSensorGesturePluginInterface : public QFactoryInterface
{
public:
+ QSensorGesturePluginInterface();
+ virtual ~QSensorGesturePluginInterface();
virtual QList <QSensorGestureRecognizer *> createRecognizers() = 0;
virtual QStringList supportedIds() const = 0;
virtual QString name() const = 0;
-
+ QStringList keys() const { return QStringList() << name(); }
};
-Q_DECLARE_INTERFACE(QSensorGesturePluginInterface, "com.Nokia.QSensorGesturePluginInterface");
-
QT_END_NAMESPACE
+Q_DECLARE_INTERFACE(QSensorGesturePluginInterface, QSensorGestureFactoryInterface_iid);
#endif // QSENSORGESTUREPLUGININTERFACE_H
diff --git a/src/sensors/qmobilitypluginsearch.h b/src/sensors/qmobilitypluginsearch.h
deleted file mode 100644
index 045da296..00000000
--- a/src/sensors/qmobilitypluginsearch.h
+++ /dev/null
@@ -1,173 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtSensors module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** GNU Lesser General Public License Usage
-** This file may be used under the terms of the GNU Lesser General Public
-** License version 2.1 as published by the Free Software Foundation and
-** appearing in the file LICENSE.LGPL included in the packaging of this
-** file. Please review the following information to ensure the GNU Lesser
-** General Public License version 2.1 requirements will be met:
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain additional
-** rights. These rights are described in the Nokia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU General
-** Public License version 3.0 as published by the Free Software Foundation
-** and appearing in the file LICENSE.GPL included in the packaging of this
-** file. Please review the following information to ensure the GNU General
-** Public License version 3.0 requirements will be met:
-** http://www.gnu.org/copyleft/gpl.html.
-**
-** Other Usage
-** Alternatively, this file may be used in accordance with the terms and
-** conditions contained in a signed written agreement between you and Nokia.
-**
-**
-**
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QMOBILITYPLUGINSEARCH_H
-#define QMOBILITYPLUGINSEARCH_H
-
-#include <QCoreApplication>
-#include <QStringList>
-#include <QDir>
-#include <QDebug>
-
-#if defined(Q_OS_SYMBIAN)
-# include <f32file.h>
-#endif
-
-QT_BEGIN_NAMESPACE
-
-#if defined(Q_OS_SYMBIAN)
-static inline bool qSymbian_CheckDir(const QDir& dir, RFs& rfs)
-{
- bool pathFound = false;
- // In Symbian, going cdUp() in a c:/private/<uid3>/ will result in *platsec* error at fileserver (requires AllFiles capability)
- // Also, trying to cd() to a nonexistent directory causes *platsec* error. This does not cause functional harm, but should
- // nevertheless be changed to use native Symbian methods to avoid unnecessary platsec warnings (as per qpluginloader.cpp).
- // Use native Symbian code to check for directory existence, because checking
- // for files from under non-existent protected dir like E:/private/<uid> using
- // QDir::exists causes platform security violations on most apps.
- QString nativePath = QDir::toNativeSeparators(dir.absolutePath());
- TPtrC ptr = TPtrC16(static_cast<const TUint16*>(nativePath.utf16()), nativePath.length());
- TUint attributes;
- TInt err = rfs.Att(ptr, attributes);
- if (err == KErrNone) {
- // yes, the directory exists.
- pathFound = true;
- }
- return pathFound;
-}
-#define CHECKDIR(dir) qSymbian_CheckDir(dir, rfs)
-#else
-#define CHECKDIR(dir) (dir).exists()
-#endif
-
-inline QStringList mobilityPlugins(const QString& plugintype)
-{
-#if !defined QT_NO_DEBUG
- const bool showDebug = qgetenv("QT_DEBUG_PLUGINS").toInt() > 0;
-#endif
-
- QStringList paths = QCoreApplication::libraryPaths();
-/*#ifdef QTM_PLUGIN_PATH
- paths << QLatin1String(QTM_PLUGIN_PATH);
-#endif*/
-#if !defined QT_NO_DEBUG
- if (showDebug)
- qDebug() << "Plugin paths:" << paths;
-#endif
-
-#if defined(Q_OS_SYMBIAN)
- RFs rfs;
- qt_symbian_throwIfError(rfs.Connect());
-#endif
-
- // Temp variable to avoid multiple identical paths
- // (we don't convert the list to set first, because that loses the order)
- QSet<QString> processed;
-
- /* The list of discovered plugins */
- QStringList plugins;
-
- /* Enumerate our plugin paths */
- for (int i=0; i < paths.count(); i++) {
- if (processed.contains(paths.at(i)))
- continue;
- processed.insert(paths.at(i));
- QDir pluginsDir(paths.at(i));
- if (!CHECKDIR(pluginsDir))
- continue;
-
-#if defined(Q_OS_WIN)
- if (pluginsDir.dirName().toLower() == QLatin1String("debug") || pluginsDir.dirName().toLower() == QLatin1String("release"))
- pluginsDir.cdUp();
-#elif defined(Q_OS_MAC)
- if (pluginsDir.dirName() == QLatin1String("MacOS")) {
- pluginsDir.cdUp();
- pluginsDir.cdUp();
- pluginsDir.cdUp();
- }
-#endif
-
- QString subdir(QLatin1String("plugins/"));
- subdir += plugintype;
- if (pluginsDir.path().endsWith(QLatin1String("/plugins"))
- || pluginsDir.path().endsWith(QLatin1String("/plugins/")))
- subdir = plugintype;
-
- if (CHECKDIR(QDir(pluginsDir.filePath(subdir)))) {
- pluginsDir.cd(subdir);
- QStringList files = pluginsDir.entryList(QDir::Files);
-
-#if !defined QT_NO_DEBUG
- if (showDebug)
- qDebug() << "Looking for " << plugintype << " plugins in" << pluginsDir.path() << files;
-#endif
-
- for (int j=0; j < files.count(); j++) {
- plugins << pluginsDir.absoluteFilePath(files.at(j));
- }
- }
- }
-
- /* Add application path + plugintype */
- QDir appldir(QCoreApplication::applicationDirPath());
- if (appldir.cd(plugintype)) {
- if (!processed.contains(appldir.absolutePath())){
- processed.insert(appldir.absolutePath());
- QStringList files = appldir.entryList(QDir::Files);
-#if !defined QT_NO_DEBUG
- if (showDebug)
- qDebug() << "Looking for " << plugintype << " plugins in" << appldir.path() << files;
-#endif
- for (int j=0; j < files.count(); j++) {
- plugins << appldir.absoluteFilePath(files.at(j));
- }
- }
- }
-
-#if defined(Q_OS_SYMBIAN)
- rfs.Close();
-#endif
- return plugins;
-}
-
-QT_END_NAMESPACE
-
-#endif
diff --git a/src/sensors/qsensormanager.cpp b/src/sensors/qsensormanager.cpp
index 1978e8c5..a7714508 100644
--- a/src/sensors/qsensormanager.cpp
+++ b/src/sensors/qsensormanager.cpp
@@ -84,6 +84,7 @@ public:
bool sensorsChanged;
QList<QSensorChangesInterface*> changeListeners;
+ QSet <QObject *> seenPlugins;
Q_SIGNALS:
void availableSensorsChanged();
@@ -154,15 +155,21 @@ Q_SENSORS_EXPORT void sensors_unit_test_hook(int index)
static void initPlugin(QObject *o)
{
if (!o) return;
+
QSensorManagerPrivate *d = sensorManagerPrivate();
+ if (d->seenPlugins.contains(o))
+ return;
QSensorChangesInterface *changes = qobject_cast<QSensorChangesInterface*>(o);
if (changes)
d->changeListeners << changes;
QSensorPluginInterface *plugin = qobject_cast<QSensorPluginInterface*>(o);
- if (plugin)
+
+ if (plugin) {
+ d->seenPlugins.insert(o);
plugin->registerSensors();
+ }
}
void QSensorManagerPrivate::loadPlugins()
diff --git a/src/sensors/qsensorplugin.h b/src/sensors/qsensorplugin.h
index 17308ca7..c2f417b5 100644
--- a/src/sensors/qsensorplugin.h
+++ b/src/sensors/qsensorplugin.h
@@ -50,10 +50,15 @@
QT_BEGIN_NAMESPACE
-class Q_SENSORS_EXPORT QSensorPluginInterface
+#define QSensorFactoryInterface_iid "com.nokia.Qt.QSensorPluginInterface/1.0"
+
+class Q_SENSORS_EXPORT QSensorPluginInterface : public QFactoryInterface
{
+
public:
virtual void registerSensors() = 0;
+ virtual QStringList keys() const = 0;
+
protected:
~QSensorPluginInterface() {}
};
@@ -68,7 +73,7 @@ protected:
QT_END_NAMESPACE
-Q_DECLARE_INTERFACE(QSensorPluginInterface, "com.nokia.Qt.QSensorPluginInterface/1.0");
+Q_DECLARE_INTERFACE(QSensorPluginInterface, QSensorFactoryInterface_iid);
Q_DECLARE_INTERFACE(QSensorChangesInterface, "com.nokia.Qt.QSensorChangesInterface/1.0");
#endif
diff --git a/src/sensors/qsensorpluginloader.cpp b/src/sensors/qsensorpluginloader.cpp
index 66012f49..7c9ab71f 100644
--- a/src/sensors/qsensorpluginloader.cpp
+++ b/src/sensors/qsensorpluginloader.cpp
@@ -43,12 +43,18 @@
#include <QtCore/qcoreapplication.h>
#include <QtCore/qdir.h>
#include <QtCore/qdebug.h>
+#include <QtCore/private/qfactoryloader_p.h>
#include "qsensorplugin.h"
-#include "qmobilitypluginsearch.h"
QT_BEGIN_NAMESPACE
+
+#ifndef QT_NO_LIBRARY
+Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
+ (QSensorFactoryInterface_iid, QLatin1String("/sensors")))
+#endif
+
QSensorPluginLoader::QSensorPluginLoader()
{
load();
@@ -68,36 +74,25 @@ void QSensorPluginLoader::load()
if (!m_plugins.isEmpty())
return;
- QStringList plugins = mobilityPlugins(QLatin1String("sensors"));
bool reportErrors = (qgetenv("QT_DEBUG_PLUGINS") == "1");
/* Now discover the dynamic plugins */
- for (int i = 0; i < plugins.count(); i++) {
- QPluginLoader *loader = new QPluginLoader(plugins.at(i));
+ QFactoryLoader *l = loader();
+ foreach (const QString &key, l->keys()) {
- QObject *o = loader->instance();
+ QObject *o = l->instance(key);
if (o != 0) {
QSensorPluginInterface *p = qobject_cast<QSensorPluginInterface*>(o);
if (p != 0) {
m_plugins << o;
- m_loaders << loader;
} else {
if (reportErrors) {
- qWarning() << plugins.at(i) << "is not a QSensorPluginInterface";
+ qWarning() << key << "is not a QSensorPluginInterface";
}
- loader->unload();
- delete loader;
}
continue;
- } else {
- if (reportErrors) {
- qWarning() << loader->errorString();
- }
}
- delete o;
- loader->unload();
- delete loader;
}
}
diff --git a/src/sensors/qsensorpluginloader_p.h b/src/sensors/qsensorpluginloader_p.h
index d51b5b7c..552b3264 100644
--- a/src/sensors/qsensorpluginloader_p.h
+++ b/src/sensors/qsensorpluginloader_p.h
@@ -72,7 +72,6 @@ private:
void load();
QList<QObject*> m_plugins;
- QList<QPluginLoader *> m_loaders;
};
QT_END_NAMESPACE
diff --git a/tests/auto/qsensor/test_sensorplugin.cpp b/tests/auto/qsensor/test_sensorplugin.cpp
index c501377a..c850b676 100644
--- a/tests/auto/qsensor/test_sensorplugin.cpp
+++ b/tests/auto/qsensor/test_sensorplugin.cpp
@@ -54,7 +54,7 @@ class TestSensorPlugin : public QObject,
public QSensorBackendFactory
{
Q_OBJECT
- Q_INTERFACES(QSensorPluginInterface QSensorChangesInterface)
+ Q_INTERFACES(QSensorPluginInterface:QFactoryInterface QSensorChangesInterface)
public:
void registerSensors()
{
@@ -63,6 +63,7 @@ public:
if (recursive) return;
recursive = true;
+
// This is bad code. It caused a crash due to recursively calling
// loadPlugins() in qsensormanager.cpp (because loadPlugins() did
// not set the pluginsLoaded flag soon enough).
@@ -103,6 +104,8 @@ public:
qWarning() << "Can't create backend" << sensor->identifier();
return 0;
}
+ QStringList keys() const { return QStringList() << "test";}
+
};
REGISTER_STATIC_PLUGIN_V2(TestSensorPlugin)
@@ -114,6 +117,8 @@ public:
{
qWarning() << "Loaded the LegacySensorPlugin";
}
+ QStringList keys() const { return QStringList() << "legacy";}
+
};
REGISTER_STATIC_PLUGIN_V1(LegacySensorPlugin)
diff --git a/tests/auto/qsensorgestures/plugins/test/qtestsensorgestureplugin_p.h b/tests/auto/qsensorgestures/plugins/test/qtestsensorgestureplugin_p.h
index a87f6a0c..d37abd1d 100644
--- a/tests/auto/qsensorgestures/plugins/test/qtestsensorgestureplugin_p.h
+++ b/tests/auto/qsensorgestures/plugins/test/qtestsensorgestureplugin_p.h
@@ -45,10 +45,11 @@
#include <QObject>
#include <qsensorgestureplugininterface.h>
-class QTestSensorGesturePlugin : public QObject, QSensorGesturePluginInterface
+class QTestSensorGesturePlugin : public QObject, public QSensorGesturePluginInterface
{
Q_OBJECT
- Q_INTERFACES(QSensorGesturePluginInterface)
+ Q_INTERFACES(QSensorGesturePluginInterface:QFactoryInterface)
+
public:
explicit QTestSensorGesturePlugin();
~QTestSensorGesturePlugin();
diff --git a/tests/auto/qsensorgestures/plugins/test1/qtestsensorgestureplugindup.h b/tests/auto/qsensorgestures/plugins/test1/qtestsensorgestureplugindup.h
index b6c083bf..de96a222 100644
--- a/tests/auto/qsensorgestures/plugins/test1/qtestsensorgestureplugindup.h
+++ b/tests/auto/qsensorgestures/plugins/test1/qtestsensorgestureplugindup.h
@@ -48,7 +48,8 @@
class QTestSensorGestureDupPlugin : public QObject, public QSensorGesturePluginInterface
{
Q_OBJECT
- Q_INTERFACES(QSensorGesturePluginInterface)
+ Q_INTERFACES(QSensorGesturePluginInterface:QFactoryInterface)
+
public:
explicit QTestSensorGestureDupPlugin();
~QTestSensorGestureDupPlugin();
diff --git a/tests/auto/sensors2qmlapi/qbackends.h b/tests/auto/sensors2qmlapi/qbackends.h
index 01bfa36a..de1c5c02 100644
--- a/tests/auto/sensors2qmlapi/qbackends.h
+++ b/tests/auto/sensors2qmlapi/qbackends.h
@@ -55,7 +55,7 @@ class TestSensorPlugin : public QObject,
public QSensorBackendFactory
{
Q_OBJECT
- Q_INTERFACES(QSensorPluginInterface QSensorChangesInterface)
+ Q_INTERFACES(QSensorPluginInterface:QFactoryInterface QSensorChangesInterface)
public:
void registerSensors()
{
@@ -95,6 +95,7 @@ public:
qWarning() << "Can't create backend" << sensor->identifier();
return 0;
}
+ QStringList keys() const { return QStringList() << "test";}
public:
static QDeclAccelerometer* stAccel;
static QDeclAmbientLightSensor* stAbl;
diff --git a/tests/auto/sensors2qmlapi/qtemplategestureplugin.h b/tests/auto/sensors2qmlapi/qtemplategestureplugin.h
index 04e2662e..cf41e9c6 100644
--- a/tests/auto/sensors2qmlapi/qtemplategestureplugin.h
+++ b/tests/auto/sensors2qmlapi/qtemplategestureplugin.h
@@ -47,10 +47,10 @@
#include <qsensorgestureplugininterface.h>
-class QTemplateGesturePlugin : public QObject, QSensorGesturePluginInterface
+class QTemplateGesturePlugin : public QObject, public QSensorGesturePluginInterface
{
Q_OBJECT
- Q_INTERFACES(QSensorGesturePluginInterface)
+ Q_INTERFACES(QSensorGesturePluginInterface:QFactoryInterface)
public:
explicit QTemplateGesturePlugin();
~QTemplateGesturePlugin();