Reading own metadata within a Qt plugin class Reading own metadata within a Qt plugin class json json

Reading own metadata within a Qt plugin class


You do not need to know the absolute plugin file path for QPluginLoader, so you would be safe.

You can just pass the plugin name, and it will work fine. It will also return the fully-qualified file name of the plugin, including the full path to the plugin if you are reading the file name back with the corresponding method. It will be clear for the class based on the information that can be obtained from QCoreApplication::libraryPaths().

Here is the corresponding part of the documentation:

When loading the plugin, QPluginLoader searches in the current directory and in all plugin locations specified by QCoreApplication::libraryPaths(), unless the file name has an absolute path. After loading the plugin successfully, fileName() returns the fully-qualified file name of the plugin, including the full path to the plugin if one was given in the constructor or passed to setFileName().

Therefore, what you could do basically is this:

myPluginLoader.metaData().value("MetaData").toObject().value("foo").toString()

where foo can be either of your aforementioned keys.