Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Access json metadata from the plugin itself.
QtWS25 Last Chance

Access json metadata from the plugin itself.

Scheduled Pinned Locked Moved Unsolved General and Desktop
qpluginloaderqpluginjsonmetadataplugin
1 Posts 1 Posters 476 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Petross404_Petros S
    wrote on 30 Mar 2022, 19:48 last edited by
    #1

    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 with QPluginLoader::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 by Driver:

    /*!
     * `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 from QProcess 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.

    1 Reply Last reply
    0

    1/1

    30 Mar 2022, 19:48

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved