How do you completely delete (and deallocate memory) a QStringList?
Is emptying a QStringList the same as deleting it?
Thanks.
How do you completely delete (and deallocate memory) a QStringList?
Is emptying a QStringList the same as deleting it?
Thanks.
From the docs -
You dont have pointers stored in QStringList,,only objects. So When you clear it, the object must be deleted or whatever. You should not be concerned about it.QStringList inherits from QList<QString>.
Unless you used something like - QList<QString*>.
timmu (17th December 2009)
Does this mean that the following will delete a QStringList:
Can the same logic be used to delete a QTableWidget?
No.Can the same logic be used to delete a QTableWidget?
You only "delete" heap allocated objects (i.e. stuff allocated with new).
Use delete (or deleteLater()).
Stack-allocated stuff like your QStringList is "destroyed" when it goes out of scope.
Qt Code:
{ QStringList xyz; ... } // xyz is destroyed here automaticallyTo copy to clipboard, switch view to plain text mode
Heap:
Heap-allocation is slower and more error-prone. So don't use it when stack based allocation is good enough for your needs.Qt Code:
... delete heap_sl;To copy to clipboard, switch view to plain text mode
The deletion can be done by using
qDeleteAll(...)
This will call the delete function on each element inside the specified container.
Darshan
but please note the difference between
and
qDeleteAll only makes sense for the former; but also note that a QStringList is probably the better choice anyway.
Last edited by caduel; 18th December 2009 at 13:37. Reason: typo
Bookmarks