From 1767e21123a6b3d9bfa71027ad42cb16b43f7b4f Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 30 Apr 2012 12:31:48 +0200 Subject: [PATCH] Allow loading of static plugins by index 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 Reviewed-by: Thiago Macieira --- src/corelib/plugin/qfactoryloader.cpp | 29 ++++++++++++++++++--------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/corelib/plugin/qfactoryloader.cpp b/src/corelib/plugin/qfactoryloader.cpp index 3f192ea477..fc9e94037f 100644 --- a/src/corelib/plugin/qfactoryloader.cpp +++ b/src/corelib/plugin/qfactoryloader.cpp @@ -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 staticPlugins = QLibraryPrivate::staticPlugins(); + if (index < staticPlugins.size()) + return staticPlugins.at(index).instance(); + return 0; }