[Interest] Avoiding COW with Qt Containers.

Giuseppe D'Angelo giuseppe.dangelo at kdab.com
Fri May 18 23:48:08 CEST 2018


Il 18/05/2018 21:27, Jason H ha scritto:
> I've got a QVariantMap that contains QVariantMaps. (I kinda posted about this Wednesday, when I was having a few issues at the same time).
> I'm essentially trying to do
> 
> map["a"]["b"]["c"] = QPoint(0,0);
> 
> However, because I'm using QVariant maps, I have to do:
> QVariantMap a = map["a"].toMap();
> QVariantMap b = a["b"].toMap();
> b["c"]=QPoint(0,0);
> 
> But that detaches from b and gives me a new container modified b, and it doesnt appear in the hierarchy. I have to:

This has nothing to do with detaching / COW; this has to do with the 
fact that toMap() gives you a _copy_ of the contents of the variant at 
a["b"]. From that moment on you're modifying b, which is a totally 
independent object from the one contained in a["b"]. As far as I know, 
there's no API to avoid the copy and reference directly the contents of 
a variant.

My 2 c,
-- 
Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4007 bytes
Desc: Firma crittografica S/MIME
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20180518/28eaeaf5/attachment.bin>


More information about the Interest mailing list