Looking for qt Keywords? Try Ask4Keywords

QtImplizite Freigabe


Bemerkungen

STL-Stil-Iteratoren für Qt-Container können aufgrund des impliziten Austauschs negative Auswirkungen haben. Es wird empfohlen, das Kopieren eines Qt-Containers zu vermeiden, wenn Iteratoren aktiv sind.

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!

Implizite Freigabe Verwandte Beispiele