There is the following hierarchy: QVariantMap <- QVariantList <- QVariantMap
The problem is QVariant::toList() and QVariant::toMap() return copies, which means I can't change value in a nested QVariantMap or QVariantList.
Is there any way to solse it?
P.S. I tried QJsonObject instead (because it's easy to convert it to a QVariantMap) but faced the same problem: I could not change QJsonObject stored in QJsonArray because operator[] for QJsonObject marked as const (and it was also problematic for me to work with QJsonValue and ULongLong together, so I returned to QVariant).
Hierarchy:
QVariantMap mainTable;
QVariantList list;
QVariantMap subTable;
subTable["id"] = 0;
list << subtable;
mainTable["list"] = list;
I've got no issues with filling it but when I tried to change stored values later (in other methods) there was the problem, because I can't change subTable["id"] value like:
mainTable["list"].toList()[index].toMap()["id"] = 12;
At first glance, I can't see other solution for your problem than this, it may be heavy...
running this code gives me