Allow loading of static plugins by index
authorLars Knoll <lars.knoll@nokia.com>
Mon, 30 Apr 2012 10:31:48 +0000 (12:31 +0200)
committerQt by Nokia <qt-info@nokia.com>
Tue, 1 May 2012 05:10:37 +0000 (07:10 +0200)
Static plugins could so far not get loaded by
index. Implement the missing support for this.

Task-number: QTBUG-25274
Change-Id: I901b08bfaf4f9fc3cb9fcea0b47f3ed89588a27b
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
src/corelib/plugin/qfactoryloader.cpp

index 3f192ea..fc9e940 100644 (file)
@@ -326,20 +326,29 @@ QObject *QFactoryLoader::instance(const QString &key) const
 QObject *QFactoryLoader::instance(int index) const
 {
     Q_D(const QFactoryLoader);
-    if (index < 0 || index >= d->libraryList.size())
+    if (index < 0)
         return 0;
 
-    QLibraryPrivate *library = d->libraryList.at(index);
-    if (library->instance || library->loadPlugin()) {
-        if (!library->inst)
-            library->inst = library->instance();
-        QObject *obj = library->inst.data();
-        if (obj) {
-            if (!obj->parent())
-                obj->moveToThread(QCoreApplicationPrivate::mainThread());
-            return obj;
+    if (index < d->libraryList.size()) {
+        QLibraryPrivate *library = d->libraryList.at(index);
+        if (library->instance || library->loadPlugin()) {
+            if (!library->inst)
+                library->inst = library->instance();
+            QObject *obj = library->inst.data();
+            if (obj) {
+                if (!obj->parent())
+                    obj->moveToThread(QCoreApplicationPrivate::mainThread());
+                return obj;
+            }
         }
+        return 0;
     }
+
+    index -= d->libraryList.size();
+    QVector<QStaticPlugin> staticPlugins = QLibraryPrivate::staticPlugins();
+    if (index < staticPlugins.size())
+        return staticPlugins.at(index).instance();
+
     return 0;
 }