1

Q_PLUGIN_METADATA(IID "descComponentIID" FILE "file.json")

How to utilize the json file for configuring a component. My Purpose is to store the configuration of a component like if its a paint canvas component then storing the size of the canvas or the background colour of the component?

codeKarma
  • 117
  • 8

2 Answers2

0

//Suppose A JSON file is created Example Test.json

{ "Name" : "Test", "Version" : "1.0.1", "CompatVersion" : "1.0.0", "Vendor" : "My Company", "Copyright" : "(C) 2016 MyCompany", "License" : [ "This is a default license bla", "blubbblubb", "end of terms" ] }

//Now Access metadata with the PluingLoader Which is used to load the

QJsonObject QPluginLoader::metaData() const

//The QJsonObject can be resursively traversed and QJsonValue can be

QJsonValue take(QLatin1String key)

codeKarma
  • 117
  • 8
0

I will post a small draft to help me provide an explanation.

nmplugin.json

{
    "name": "nm",
    "arguments": "--some-args"
}

You must access the "Metadata" key before any other entry in the json file. Don't forget to test the returned QJsonValue with isUndefined() to be on the safe side.

QJsonObject object{ loader->metaData().value("MetaData").toObject() };
qDebug() << object.value("name"); // Will print "nm"
Petross404
  • 177
  • 1
  • 12