[Interest] Why no T& QVariant::value()?

Jason H jhihn at gmx.com
Wed May 23 16:16:41 CEST 2018


Really wishing this function existed. Can someone explain why it doesnt' exist?

I'm using it in conjunction with QVariantMap and QVariant list, where I want to change the value held at key or index. But in a nested map or list, since value() returns a copy, the change does not persist in the container.

QVariantMap mapOfMap;
QVariantMap map {{"key", QRect(0,0,5,5)}};
mapOfMap["map"]=map;
mapOfMap["map"].toMap()["key"] = QRect(1,1,6,6); // copies all the way down, changed a copy of mapOfMap["map"].toMap()["key"], gets discarded
map = mapOfMap["map"].toMap();
map["key"] = QRect(1,1,6,6); // changed a copy of mapOfMap["map"].toMap()["key"]
mapOfMap["map"]=map // but we set the copy to be in the original map, so it'll stay

Help?



More information about the Interest mailing list