<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[deleting a QMap after clear()]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">is it safe to call delete directly after having called clear() on a QMap.<br />
e.g. :</p>
<p dir="auto">QMap *myMap = new QMap&lt;QString,MyClass&gt;<br />
myMap-&gt;insert("one", myClass);<br />
....<br />
myMap-&gt;clear();<br />
delete myMap;</p>
]]></description><link>https://forum.qt.io/topic/98425/deleting-a-qmap-after-clear</link><generator>RSS for Node</generator><lastBuildDate>Sat, 02 May 2026 01:48:43 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/98425.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 11 Jan 2019 15:34:44 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to deleting a QMap after clear() on Fri, 11 Jan 2019 18:46:36 GMT]]></title><description><![CDATA[<p dir="auto">And to complete it all together - there is no need to create a QMap on the heap at all in most of the cases.</p>
]]></description><link>https://forum.qt.io/post/504168</link><guid isPermaLink="true">https://forum.qt.io/post/504168</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Fri, 11 Jan 2019 18:46:36 GMT</pubDate></item><item><title><![CDATA[Reply to deleting a QMap after clear() on Fri, 11 Jan 2019 16:11:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dheerendra">@<bdi>dheerendra</bdi></a><br />
I simply meant that calling clear deletes QMaps internal structures holding the items it manages.<br />
But good call noting if MyClass is a pointer , clear() will not be delete the object being pointed to, but only the pointer itself.</p>
]]></description><link>https://forum.qt.io/post/504149</link><guid isPermaLink="true">https://forum.qt.io/post/504149</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Fri, 11 Jan 2019 16:11:27 GMT</pubDate></item><item><title><![CDATA[Reply to deleting a QMap after clear() on Fri, 11 Jan 2019 16:06:25 GMT]]></title><description><![CDATA[<p dir="auto">If your value objects are pointer type, you should delete them as well.</p>
<blockquote>
<p dir="auto">will delete the internal structures.<br />
<a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> curious about above statement. What do you mean by it ?</p>
</blockquote>
]]></description><link>https://forum.qt.io/post/504148</link><guid isPermaLink="true">https://forum.qt.io/post/504148</guid><dc:creator><![CDATA[dheerendra]]></dc:creator><pubDate>Fri, 11 Jan 2019 16:06:25 GMT</pubDate></item><item><title><![CDATA[Reply to deleting a QMap after clear() on Fri, 11 Jan 2019 15:47:44 GMT]]></title><description><![CDATA[<p dir="auto">hi and welcome to the forums<br />
yes it should be.<br />
The clear happens in place and will delete the internal structures.</p>
]]></description><link>https://forum.qt.io/post/504145</link><guid isPermaLink="true">https://forum.qt.io/post/504145</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Fri, 11 Jan 2019 15:47:44 GMT</pubDate></item></channel></rss>