隐含共享

由于隐式共享,Qt 容器上的 STL 样式迭代器可能会产生一些负面影响。建议在迭代器处于活动状态时避免复制 Qt 容器。

QVector<int> a,b; //2 vectors
a.resize(1000); 
b = a; // b and a now point to the same memory internally

auto iter = a.begin(); //iter also points to the same memory a and b do
a[4] = 1; //a creates a new copy and points to different memory.
//Warning 1: b and iter point sill to the same even if iter was "a.begin()"

b.clear(); //delete b-memory
//Warning 2: iter only holds a pointer to the memory but does not increase ref-count. 
//           so now the memory iter points to is invalid. UB!