diff options
Diffstat (limited to 'src/corelib/plugin/qfactoryloader_p.h')
-rw-r--r-- | src/corelib/plugin/qfactoryloader_p.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/corelib/plugin/qfactoryloader_p.h b/src/corelib/plugin/qfactoryloader_p.h index ee7a68d6f8..66ded8074b 100644 --- a/src/corelib/plugin/qfactoryloader_p.h +++ b/src/corelib/plugin/qfactoryloader_p.h @@ -56,6 +56,7 @@ #include "QtCore/qobject.h" #include "QtCore/qstringlist.h" #include "QtCore/qjsonobject.h" +#include "QtCore/qmap.h" #include "private/qlibrary_p.h" #ifndef QT_NO_LIBRARY @@ -84,11 +85,42 @@ public: QLibraryPrivate *library(const QString &key) const; #endif + QMultiMap<int, QString> keyMap() const; + int indexOf(const QString &needle) const; + void update(); static void refreshAll(); }; +template <class PluginInterface, class FactoryInterface> + PluginInterface *qLoadPlugin(const QFactoryLoader *loader, const QString &key) +{ + const int index = loader->indexOf(key); + if (index != -1) { + QObject *factoryObject = loader->instance(index); + if (FactoryInterface *factory = qobject_cast<FactoryInterface *>(factoryObject)) + if (PluginInterface *result = factory->create(key)) + return result; + } + return 0; +} + +template <class PluginInterface, class FactoryInterface, class Parameter1> +PluginInterface *qLoadPlugin1(const QFactoryLoader *loader, + const QString &key, + const Parameter1 ¶meter1) +{ + const int index = loader->indexOf(key); + if (index != -1) { + QObject *factoryObject = loader->instance(index); + if (FactoryInterface *factory = qobject_cast<FactoryInterface *>(factoryObject)) + if (PluginInterface *result = factory->create(key, parameter1)) + return result; + } + return 0; +} + QT_END_NAMESPACE #endif // QT_NO_LIBRARY |