Accessing the Plugin metadata starting from a QObject*
-
Supposing I maintain a list of QObject* that was retrieved via QPluginLoader::instance() and via QPluginLoader::staticPlugins().
I am looking for a simple way to retrieve the plugin metaData starting from the QObject*
@Lolo67 Check the documentation: http://doc.qt.io/qt-5/qpluginloader.html#instance
"The component object is a QObject. Use qobject_cast() to access interfaces you are interested in." -
I don't see how qobject_cast() could bring me to the metaData defined via Q_PLUGIN_METADATA.
@Lolo67 What about http://doc.qt.io/qt-5/qpluginloader.html#metaData and http://doc.qt.io/qt-5/qstaticplugin.html#metaData?
It's all in the documentation... -
It is not in the documentation.
metaData() is a method of the QPluginLoader, not the QObject instance, as returned by QPluginLoader::instance(). There is no way, at least not documented from e.g. (QObject*)(this) to the metadata.
E.g.
QPluginLoader loader("my/plugins/foo.so"); // metadata is available here: auto meta = loader.metaData(); auto foo = loader.instance(); auto bar = qobject_cast<BarInterface>(foo); ... Class Foo : public BarInterface { Foo::Foo() { // this->metaData() - not accessible here } };Unless the metaData is passed back from the loader to the plugin instance, it seems to be unavailable.
-
It is not in the documentation.
metaData() is a method of the QPluginLoader, not the QObject instance, as returned by QPluginLoader::instance(). There is no way, at least not documented from e.g. (QObject*)(this) to the metadata.
E.g.
QPluginLoader loader("my/plugins/foo.so"); // metadata is available here: auto meta = loader.metaData(); auto foo = loader.instance(); auto bar = qobject_cast<BarInterface>(foo); ... Class Foo : public BarInterface { Foo::Foo() { // this->metaData() - not accessible here } };Unless the metaData is passed back from the loader to the plugin instance, it seems to be unavailable.
@StefanBruens said in Accessing the Plugin metadata starting from a QObject*:
Unless the metaData is passed back from the loader to the plugin instance, it seems to be unavailable.
The meta data is not available through the
QObject, get it from the loader if you need it. Strictly speakingQ_PLUGIN_METADATAis a moc artifact that facilitates the plugin loading and you shouldn't really need it to begin with, while on the other hand theQObjectyou get isn't a plugin it's the entry point for the plugin.