[Solved]QVariant to QList
-
I have a QVariantMap, and values are QVariantMaps or QStringList, or map with lists... but when I call .toStringList() or .toList() it works fine, but after calling .clear(), removeAt(), takeAt() or something similar, it does nothing! what i am doing wrong?
@myMap.value("value").toMap().value("otherValue").toStringList().removeOne("something");@
-
toStringList() returns a copy of the list, not a reference. So any changes you make are immediately discarded.
-
Okay, so how can I remove something from that list?
-
@
QStringList templist = myMap.value("value").toMap().value("otherValue").toStringList();
templist.removeOne("something");
myMap.value("value").toMap().insert("otherValue",templist);
@Brain to terminal. YMMV.
Basically grab a copy of the list, modify the copy, then reinsert back into your map.
-
yes, it was my first guess, but it doesnt work...
-
Ah, the toMap() also returns a copy, btw. Same issue, just next level up. Need a temp QMap, as well.
-
Thank you, it works now