Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
deleting a QMap after clear()
nemd last edited by
is it safe to call delete directly after having called clear() on a QMap.
QMap *myMap = new QMap<QString,MyClass>
hi and welcome to the forums
yes it should be.
The clear happens in place and will delete the internal structures.
If your value objects are pointer type, you should delete them as well.
will delete the internal structures.
@mrjj curious about above statement. What do you mean by it ?
I simply meant that calling clear deletes QMaps internal structures holding the items it manages.
But good call noting if MyClass is a pointer , clear() will not be delete the object being pointed to, but only the pointer itself.
And to complete it all together - there is no need to create a QMap on the heap at all in most of the cases.