<?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[Allocating memory in Desctructor for deleting QHash values]]></title><description><![CDATA[<p dir="auto">Hello ! :)</p>
<p dir="auto">is there a QHash method which returns one key or its hashed value (as a reference)?</p>
<p dir="auto">I attempt to delete objects stored as values in a QHash in the Destructor of a class of mine.</p>
<p dir="auto">I only found the method keys() to get all keys of the hash which requires allocating a QList, or don't I have to allocate a QList?</p>
<p dir="auto">If the keys() method fails due to memory constraints, I can't destruct my class, (because I don't get the keys which I need to find the values to delete) or can I ?</p>
<p dir="auto">Or is there an other approach to this kind of destructing?</p>
<p dir="auto">Thank you for your attempt and Best Regards!</p>
]]></description><link>https://forum.qt.io/topic/28431/allocating-memory-in-desctructor-for-deleting-qhash-values</link><generator>RSS for Node</generator><lastBuildDate>Thu, 23 Apr 2026 07:55:56 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/28431.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 18 Jun 2013 15:21:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Allocating memory in Desctructor for deleting QHash values on Tue, 18 Jun 2013 15:50:57 GMT]]></title><description><![CDATA[<p dir="auto">I'm not sure. Probably it's already allocated when you create the hash. Take a look at the code if you are so inclined, or use a profiler to see what happens at runtime.</p>
<p dir="auto">"QObject":<a href="http://qt-project.org/doc/qt-4.8/metaobjects.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://qt-project.org/doc/qt-4.8/metaobjects.html</a> stuff is here. It does introduce overhead, so if your device is low on memory and you have a lot of objects to create, then maybe it's not a good idea.</p>
]]></description><link>https://forum.qt.io/post/183309</link><guid isPermaLink="true">https://forum.qt.io/post/183309</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Tue, 18 Jun 2013 15:50:57 GMT</pubDate></item><item><title><![CDATA[Reply to Allocating memory in Desctructor for deleting QHash values on Tue, 18 Jun 2013 15:46:05 GMT]]></title><description><![CDATA[<p dir="auto">Yes, I read that. Does creating the QHashIterator not allocate memory?<br />
The values are of a custom-made class. Can I read up on the benefit of deriving of QObject somewhere? Where?<br />
Thank you.</p>
]]></description><link>https://forum.qt.io/post/183307</link><guid isPermaLink="true">https://forum.qt.io/post/183307</guid><dc:creator><![CDATA[1231]]></dc:creator><pubDate>Tue, 18 Jun 2013 15:46:05 GMT</pubDate></item><item><title><![CDATA[Reply to Allocating memory in Desctructor for deleting QHash values on Tue, 18 Jun 2013 15:39:37 GMT]]></title><description><![CDATA[<p dir="auto">You can go thorough all values with:<br />
@<br />
QHashIterator&lt;QString, int&gt; i(hash);<br />
while (i.hasNext()) {<br />
i.next();<br />
cout &lt;&lt; i.key() &lt;&lt; ": " &lt;&lt; i.value() &lt;&lt; endl;<br />
}<br />
@</p>
<p dir="auto">As mentioned in - surprise! - "official documentation":<a href="http://qt-project.org/doc/qt-5.0/qtcore/qhash.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://qt-project.org/doc/qt-5.0/qtcore/qhash.html</a>. Also, remember that if your values are QObject pointers that are properly parented, you don't need to delete them, Qt will do it for you.</p>
]]></description><link>https://forum.qt.io/post/183304</link><guid isPermaLink="true">https://forum.qt.io/post/183304</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Tue, 18 Jun 2013 15:39:37 GMT</pubDate></item></channel></rss>