I have a json object that I load:
QJsonObject json = CommonToolkit::Types::LoadJson(config);
Here is a partial of the json file content:
{
"config": {
"macos": {
"screen": {
"main": {
"height": 0,
"left": 0,
"top": 0,
"width": 0
}
},
"windows: {
}
What I do is check what os i'm running in. Using the following variable to store that os:
QString osPath;
In my test osPath = "macos"
So I want to update the applications geometry
QJsonObject jparam{
{ "height", value.height() },
{ "left", value.left() },
{ "width", value.width() },
{ "top", value.top() }
};
My problem is when I try to set jon with jparam using osPath:
json["config"][osPath]["screen"]["main"] = jparam;
The error I'm getting is:
/Users/adviner/Projects/Notes/src/Notes/data/config.cpp:87: error: type 'QJsonValueRef' does not provide a subscript operator json["config"][osPath]["screen"]["main"] = jparam; ~~~~~~~~~~~~~~^~~~~~~
Editing a Json in Qt is not a simple task, in this case when using
json["config"]
you get aQJsonValueRef
, this class is a helper to get other types of elements likeQJsonObject
,QJsonArray
,int
,QString
, etc. by what to get the next element must be usedtoObject()
but this value is a copy, so if you modify it, the initial element will not be modified, you have to reassign it.