To elaborate: destroying a QList will destroy the elements of the list. If the elements are pointers, the pointers themselves are destroyed, not the pointees. You can use qDeleteAll
to delete the pointees.
(That will use operator delete
, which is the right choice if and only if you're using operator new
; malloc
will always require free
and operator new[]
will always require operator delete[]
).
That having been said, returning a QList by value won't destroy it, as its refcount won't drop to 0. Getting a crash there means it's very likely that you have some memory corruption. Use valgrind or similar tools to debug that.