<?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[How to use QHash &#x2F; MusltiHash - hint needed]]></title><description><![CDATA[<p dir="auto">Hi to all,</p>
<p dir="auto">I want to create a QHash(Multi), which has the following content (Pseudo)example:</p>
<pre><code>"QString Key" -&gt;  int val 1, int val2, int val3
</code></pre>
<p dir="auto">Is this possible and if yes - how?</p>
<p dir="auto">thx and regards Alex</p>
]]></description><link>https://forum.qt.io/topic/138997/how-to-use-qhash-musltihash-hint-needed</link><generator>RSS for Node</generator><lastBuildDate>Tue, 12 May 2026 18:11:06 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/138997.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 31 Aug 2022 12:52:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to use QHash &#x2F; MusltiHash - hint needed on Thu, 01 Sep 2022 07:00:46 GMT]]></title><description><![CDATA[<p dir="auto">I am not sure that the OP is actually looking for a multi hash. A multi hash stores any number of entries under the same hash key. In the case that you always want to store exactly 3 integers combine the hash with a tuple:<br />
<code>QHash&lt;QString,std::tuple&lt;int,int,int&gt;&gt; hash;</code><br />
You can then access the second value with <code>std::get&lt;1&gt;(hash["key"])</code>. Notice that in C++ we <strong>always</strong> start counting from 0. So the <em>second</em> value has index 1.</p>
<p dir="auto">I personally consider using a tuple the quick &amp; dirty approach. If your three integers have a specific purpose it is much better to write a little struct:</p>
<pre><code>struct my_data_t
{
  int a;
  int b;
  int c;
};

QHash&lt;QString,my_data_t&gt; hash;
...
hash["key"].b;
</code></pre>
]]></description><link>https://forum.qt.io/post/726994</link><guid isPermaLink="true">https://forum.qt.io/post/726994</guid><dc:creator><![CDATA[SimonSchroeder]]></dc:creator><pubDate>Thu, 01 Sep 2022 07:00:46 GMT</pubDate></item><item><title><![CDATA[Reply to How to use QHash &#x2F; MusltiHash - hint needed on Thu, 01 Sep 2022 13:58:58 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ademmler">@<bdi>ademmler</bdi></a> said in <a href="/post/727046">How to use QHash / MusltiHash - hint needed</a>:</p>
<blockquote>
<p dir="auto">It could be a fixed set of entries - which might not be modified.</p>
</blockquote>
<p dir="auto">Then a multihash is not the correct container as already pointed out by <a class="plugin-mentions-user plugin-mentions-a" href="/user/simonschroeder">@<bdi>SimonSchroeder</bdi></a></p>
]]></description><link>https://forum.qt.io/post/727057</link><guid isPermaLink="true">https://forum.qt.io/post/727057</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Thu, 01 Sep 2022 13:58:58 GMT</pubDate></item><item><title><![CDATA[Reply to How to use QHash &#x2F; MusltiHash - hint needed on Thu, 01 Sep 2022 12:58:44 GMT]]></title><description><![CDATA[<p dir="auto">Hi Christian,</p>
<p dir="auto">It could be a fixed set of entries - which might not be modified.<br />
However <a class="plugin-mentions-user plugin-mentions-a" href="/user/simonschroeder">@<bdi>SimonSchroeder</bdi></a> gave me a nice idea what to do.</p>
<p dir="auto">thx guys.</p>
]]></description><link>https://forum.qt.io/post/727046</link><guid isPermaLink="true">https://forum.qt.io/post/727046</guid><dc:creator><![CDATA[ademmler]]></dc:creator><pubDate>Thu, 01 Sep 2022 12:58:44 GMT</pubDate></item><item><title><![CDATA[Reply to How to use QHash &#x2F; MusltiHash - hint needed on Thu, 01 Sep 2022 07:00:46 GMT]]></title><description><![CDATA[<p dir="auto">I am not sure that the OP is actually looking for a multi hash. A multi hash stores any number of entries under the same hash key. In the case that you always want to store exactly 3 integers combine the hash with a tuple:<br />
<code>QHash&lt;QString,std::tuple&lt;int,int,int&gt;&gt; hash;</code><br />
You can then access the second value with <code>std::get&lt;1&gt;(hash["key"])</code>. Notice that in C++ we <strong>always</strong> start counting from 0. So the <em>second</em> value has index 1.</p>
<p dir="auto">I personally consider using a tuple the quick &amp; dirty approach. If your three integers have a specific purpose it is much better to write a little struct:</p>
<pre><code>struct my_data_t
{
  int a;
  int b;
  int c;
};

QHash&lt;QString,my_data_t&gt; hash;
...
hash["key"].b;
</code></pre>
]]></description><link>https://forum.qt.io/post/726994</link><guid isPermaLink="true">https://forum.qt.io/post/726994</guid><dc:creator><![CDATA[SimonSchroeder]]></dc:creator><pubDate>Thu, 01 Sep 2022 07:00:46 GMT</pubDate></item><item><title><![CDATA[Reply to How to use QHash &#x2F; MusltiHash - hint needed on Thu, 01 Sep 2022 06:37:24 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ademmler">@<bdi>ademmler</bdi></a> said in <a href="/post/726989">How to use QHash / MusltiHash - hint needed</a>:</p>
<blockquote>
<p dir="auto">I could not find such a routine.  It would always need:</p>
</blockquote>
<p dir="auto">How should it work otherwise? Since you don't know how many elements you get for one value you must not directly access the third (in your case) element but check the size of the returned container first.</p>
]]></description><link>https://forum.qt.io/post/726990</link><guid isPermaLink="true">https://forum.qt.io/post/726990</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Thu, 01 Sep 2022 06:37:24 GMT</pubDate></item><item><title><![CDATA[Reply to How to use QHash &#x2F; MusltiHash - hint needed on Thu, 01 Sep 2022 06:11:39 GMT]]></title><description><![CDATA[<p dir="auto">Thx for answering:</p>
<p dir="auto">You mean this example:</p>
<pre><code>QMultiHash&lt;QString, int&gt; hash1, hash2, hash3;
hash1.insert("plenty", 100);
hash1.insert("plenty", 2000);
</code></pre>
<p dir="auto">In my example this would be:<br />
QMultiHash&lt;QString, int&gt; hash;<br />
hash.insert("plenty", 100);<br />
hash.insert("plenty", 2000);<br />
hash.insert("plenty", 50);</p>
<p dir="auto">How to access the second value? Is there something like</p>
<pre><code>hash.getValue(2);
</code></pre>
<p dir="auto">I could not find such a routine.  It would always need:</p>
<pre><code>QList&lt;int&gt; values = hash.values("plenty");   values.at(2);
</code></pre>
]]></description><link>https://forum.qt.io/post/726989</link><guid isPermaLink="true">https://forum.qt.io/post/726989</guid><dc:creator><![CDATA[ademmler]]></dc:creator><pubDate>Thu, 01 Sep 2022 06:11:39 GMT</pubDate></item><item><title><![CDATA[Reply to How to use QHash &#x2F; MusltiHash - hint needed on Wed, 31 Aug 2022 12:55:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ademmler">@<bdi>ademmler</bdi></a> said in <a href="/post/726911">How to use QHash / MusltiHash - hint needed</a>:</p>
<blockquote>
<p dir="auto">Is this possible and if yes - how?</p>
</blockquote>
<p dir="auto">Yes it is. What exactly is the problem?<br />
In documentation you can even find an example for exactly what you're asking: <a href="https://doc.qt.io/qt-5/qmultihash.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-5/qmultihash.html</a></p>
]]></description><link>https://forum.qt.io/post/726912</link><guid isPermaLink="true">https://forum.qt.io/post/726912</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Wed, 31 Aug 2022 12:55:20 GMT</pubDate></item></channel></rss>