Access json metadata from the plugin itself.
-
Hello to all.
I want to ask if I can access the metadata of the json file that is used with
Q_PLUGIN_METADATA()
in the same class that used this macro. I know I can access it withQPluginLoader::metaData()
but I want to read these entries in my plugin during construction.Let me explain:
I am having an abstract interface like this:
class IDriver //apparently no QObject inheritance here { public: IDriver(); ... }; #define IDriver_iid "org.qt.IDriver" Q_DECLARE_INTERFACE( Process::IDriver, IDriver_iid )
IDriver
is derived byDriver
:/*! * `Driver` is a concrete class for the `IDriver`. It defines some generic * fuctions for the derived `NmDriver` and `ScanelfDriver`. */ class Driver: public QProcess, public Process::IDriver { Q_OBJECT Q_DISABLE_COPY_MOVE( Driver ) public: Driver( QObject* parent = nullptr ); Driver( QString program, QStringList defArgList, QObject* parent ); ... };
Driver
also derives fromQProcess
and provides the base class for my plugins (NmDriver and ScanelfDriver):class NmDriver: public Driver // The same applies for ScanelfDriver too { Q_OBJECT Q_PLUGIN_METADATA( IID "NmDriver" FILE "nmplugin.json" ) Q_INTERFACES( Process::IDriver ) Q_DISABLE_COPY_MOVE( NmDriver ) public: NmDriver( QObject* parent = nullptr ); ... };
I can access my json entries easily using
QPluginLoader::metaData()
but I want to initialize some member variables of my plugins, with the data inside my json files. Like:NmDriver::NmDriver( QObject* parent ) : Driver{ myJsonArgsFromMetadataMacro, parent } {...
My question is this: How can I access the json file that the
Q_PLUGIN_METADATA()
used, inside the same class (ie my plugin)? If it possible at all ofcourse.Thank you very much.