<?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[qBinaryFind for QStringList]]></title><description><![CDATA[<p dir="auto">I have 2 QStringLists (L1 is a subset of L2). I need to find the <strong>index</strong> of all <strong>L1</strong> elements in <strong>L2</strong>. I am using binary search to do the same but I am not sure how to find the index. Also, please do suggest if there is a better way for doing the same.</p>
<p dir="auto">Thanks.</p>
<pre><code> for(int i=0;i&lt;filesGeotagged.length();i++){

        QList&lt;QString&gt;::iterator k = qBinaryFind(L2.begin(),L2.end(),L1[i]);
        qDebug() &lt;&lt; *k;

    }
</code></pre>
]]></description><link>https://forum.qt.io/topic/73845/qbinaryfind-for-qstringlist</link><generator>RSS for Node</generator><lastBuildDate>Thu, 09 Apr 2026 22:00:33 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/73845.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 29 Nov 2016 11:45:55 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to qBinaryFind for QStringList on Wed, 30 Nov 2016 12:00:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a></p>
<p dir="auto">It works !! Thanks.</p>
]]></description><link>https://forum.qt.io/post/362379</link><guid isPermaLink="true">https://forum.qt.io/post/362379</guid><dc:creator><![CDATA[saitej]]></dc:creator><pubDate>Wed, 30 Nov 2016 12:00:38 GMT</pubDate></item><item><title><![CDATA[Reply to qBinaryFind for QStringList on Tue, 29 Nov 2016 15:41:53 GMT]]></title><description><![CDATA[<p dir="auto">Your approach is sound. The only drawback is you'd need to sort L2 (before starting the search) for obvious reasons. Another thing you can try if your lists are long is to hash L2. For example:</p>
<pre><code>// Preparation part:
QHash&lt;QString, int&gt; indices;
indices.reserve(L2.size());
for (qint32 i = 0, size = L2.size(); i &lt; size; i++)
    indices.insert(L2.at(i), i);

// Search part:
for (qint32 i=0, size = filesGeotagged.length(); i &lt; size; i++)  {
    qDebug() &lt;&lt; indices.value(L1.at(i), -1); // Output the index, handle -1 as an error (i.e. put an assertion)
}
</code></pre>
]]></description><link>https://forum.qt.io/post/362218</link><guid isPermaLink="true">https://forum.qt.io/post/362218</guid><dc:creator><![CDATA[kshegunov]]></dc:creator><pubDate>Tue, 29 Nov 2016 15:41:53 GMT</pubDate></item><item><title><![CDATA[Reply to qBinaryFind for QStringList on Tue, 29 Nov 2016 11:52:20 GMT]]></title><description><![CDATA[<p dir="auto">Hi<br />
Not tested with Qt but<br />
Can you do</p>
<p dir="auto">int index=(k - L2.begin());<br />
?</p>
<p dir="auto">You could also use a map, if each L1 element has a good key.<br />
Then it would be direct lookup.</p>
]]></description><link>https://forum.qt.io/post/362188</link><guid isPermaLink="true">https://forum.qt.io/post/362188</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Tue, 29 Nov 2016 11:52:20 GMT</pubDate></item></channel></rss>