PDA

View Full Version : Implicit sharing iterator problem with QVector and QHash



mut
19th November 2015, 03:47
Hello

What should one pay attention to in order to avoid the Implicit sharing iterator problem in the case of QVector? same question for QHash?

Can I do:

QVector<int> a;
Qvector<int> b;

a.push_back(0);
a.push_back(1);

b.push_back(2);
b.push_back(3);

//iterate trough a
//iterate trough b
// remove one element in b

a = b;

What are the restrictions when assigning one QVector to another one?

Thank you in advance for any hints/help.

Mut.

anda_skoa
19th November 2015, 09:38
Can you elaborate what the "Implicit sharing iterator problem" is?

Your code creates one vector with two element, one with four, then iterates over both, then reduces the size of the four element vector to three and then overwrites the two element vector.

What exactly is problematic there?

Cheers,
_