[Interest] Help, please !!!

Robin Burchell robin+qt at viroteck.net
Thu Apr 26 23:07:39 CEST 2012


On Thu, Apr 26, 2012 at 10:51 PM, Andre Somers <andre at familiesomers.nl> wrote:
> The copy is made at the moment you _append_ the list, not at the moment
> you're modifying it.

actually, it's made at both points. operator[] (the non-const version)
detaches (which causes a copy, if the container's data is shared).
append also does this, as does anything else that modifies the
container. that's why it's best to use at() if you don't explicitly
need to modify the list.

otherwise:

QList<int> listone;
listone << 5 << 6 << 7;
QList<int> listtwo = listone;
listtwo[0] = 10; // if this didn't detach before writing 10, listone
would be modified, and you most certainly don't expect/want that



More information about the Interest mailing list