Expose the plugins meta data in the plugin loader
authorLars Knoll <lars.knoll@nokia.com>
Sun, 27 May 2012 09:38:36 +0000 (11:38 +0200)
committerQt by Nokia <qt-info@nokia.com>
Tue, 5 Jun 2012 06:58:00 +0000 (08:58 +0200)
add a metaData() method to QPluginLoader so that
applications can query the plugins meta data without
having to load the plugin.

Change-Id: Ic3ebb35fd3c403926326e8dd1de4176b0c48dbef
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
src/corelib/plugin/qpluginloader.cpp
src/corelib/plugin/qpluginloader.h

index f198f10..a33c4e2 100644 (file)
@@ -173,6 +173,23 @@ QObject *QPluginLoader::instance()
 }
 
 /*!
+    Returns the meta data for this plugin. The meta data is data specified
+    in a json format using the Q_PLUGIN_METADATA() macro when compiling
+    the plugin.
+
+    The meta data can be queried in a fast and inexpensive way without
+    actually loading the plugin. This makes it possible to e.g. store
+    capabilities of the plugin in there, and make the decision whether to
+    load the plugin dependent on this meta data.
+ */
+QJsonObject QPluginLoader::metaData() const
+{
+    if (!d)
+        return QJsonObject();
+    return d->metaData;
+}
+
+/*!
     Loads the plugin and returns true if the plugin was loaded
     successfully; otherwise returns false. Since instance() always
     calls this function before resolving any symbols it is not
index 0e62d36..99b44fd 100644 (file)
@@ -56,6 +56,7 @@ QT_BEGIN_HEADER
 QT_BEGIN_NAMESPACE
 
 class QLibraryPrivate;
+class QJsonObject;
 
 class Q_CORE_EXPORT QPluginLoader : public QObject
 {
@@ -68,6 +69,7 @@ public:
     ~QPluginLoader();
 
     QObject *instance();
+    QJsonObject metaData() const;
 
     static QObjectList staticInstances();