QT list question
-
If i allocate objects and place them inside a list, will the QList perform the deallocation on the objects i dynamically allocate and place in the list when the QList dies?
-
QList is an array-based list, the array expands automatically, but does not shrink automatically. According to the documentation:
bq. Note that the internal array only ever gets bigger over the life of the list. It never shrinks. The internal array is deallocated by the destructor and by the assignment operator, when one list is assigned to another.
You can call the destructor, or create a new QList and add the elements to it, then delete the original QList.
-
[quote author="maybnxtseasn" date="1330232961"]If i allocate objects and place them inside a list, will the QList perform the deallocation on the objects i dynamically allocate and place in the list when the QList dies?[/quote]
Assuming that you mean having pointers to these objects and place them in QList.
It depends on the items in your list, but not in general. If you would use QSharedPointer to store in QList, the objects will be destroyed when those references are the last ones.