Reading custom metadata in a Qt plugin class

I am currently writing my own Qt plugin for use in a Qt program. To determine the version information of the plugin, I use the metadata stored in the JSON file, as shown below:

{
    "type" :            "communication",
    "name" :            "USB-LIN-IB",
    "longname" :        "USB-LIN Communication",
    "version" :         "1.1",
    "dependencies" :    []
}

To access metadata data from outside the classes of the plugin (in the world of Qt programs), I return to them since I defined the JSON file as follows:

Q_PLUGIN_METADATA(IID "org.plugins.communications.1" FILE "USBLINCommunication.json")

Can I use a standardized and convenient way to access the same metadata from a member of a plug-in (for example, a plug-in constructor)? Of course, I could use QPluginLoader (for which I should know the path to the plugin file) or the readAll file from the JSON object. However, both methods rely on knowing the exact path of the plugin and the JSON file. It is not very reliable for me.

, ?

+4
1

QPluginLoader, .

, . , , . , QCoreApplication::libraryPaths().

:

QPluginLoader , QCoreApplication:: libraryPaths(), . fileName() , , setFileName().

, :

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

foo .

+5

Source: https://habr.com/ru/post/1536250/


All Articles