<?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[HasNext() returns true when the Qstring passed to QDirIterator is null]]></title><description><![CDATA[<p dir="auto">Using version 4.7.4 and the following code:<br />
@<br />
QDirIterator Obj(QString((*itr).c_str()), QDir::AllDirs | QDir::NoDotAndDotDot | QDir::Hidden, QDirIterator::Subdirectories);<br />
while (Obj.hasNext())<br />
{<br />
Obj.next();</p>
<p dir="auto">if(Obj.fileInfo().isDir())<br />
{<br />
std::string tempDir = Obj.filePath().toStdString() + "/";<br />
tempList.push_back(tempDir);<br />
}<br />
}<br />
@<br />
Obj.hasNext() returns false for a Qstring of "". However in 4.8.6 Obj.hasNext() returns true for a QString of "". Is this a bug? Is there anyway to make 4.8.6 work like 4.7.4?</p>
<p dir="auto"><em>[edit: added missing coding tags @ SGaist]</em></p>
]]></description><link>https://forum.qt.io/topic/42164/hasnext-returns-true-when-the-qstring-passed-to-qdiriterator-is-null</link><generator>RSS for Node</generator><lastBuildDate>Thu, 05 Nov 2026 12:23:27 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/42164.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 03 Jun 2014 15:11:38 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to HasNext() returns true when the Qstring passed to QDirIterator is null on Wed, 04 Jun 2014 15:11:14 GMT]]></title><description><![CDATA[<p dir="auto">Here is the entire code including my fix:<br />
@void Demo::FindAllSubDirs(PathList &amp;list)<br />
{<br />
// A container to store the subdirectory paths<br />
PathList tempList;</p>
<p dir="auto">for (PathList::iterator itr = list.begin(); itr != list.end(); ++itr)<br />
{<br />
tempList.push_back(*itr);<br />
if(!(QString((*itr).c_str()).isEmpty()))<br />
{<br />
QDirIterator Obj(QString((*itr).c_str()), QDir::AllDirs | QDir::NoDotAndDotDot | QDir::Hidden, QDirIterator::Subdirectories);<br />
while (Obj.hasNext())<br />
{<br />
Obj.next();</p>
<pre><code>if(Obj.fileInfo().isDir()) 
{
 std::string tempDir = Obj.filePath().toStdString() + "/";
 tempList.push_back(tempDir);
}
</code></pre>
<p dir="auto">}<br />
}<br />
}</p>
<p dir="auto">list.clear();<br />
list = tempList;<br />
}<br />
@<br />
I also replace the QDirIterator line with this line as suggested and YES it does fail as Obj.hasNext() returns true and should return false:<br />
@QDirIterator Obj(QString(""), QDir::AllDirs | QDir::NoDotAndDotDot | QDir::Hidden, QDirIterator::Subdirectories);@</p>
<p dir="auto">The list requires a null as the first entry in the list.</p>
]]></description><link>https://forum.qt.io/post/230972</link><guid isPermaLink="true">https://forum.qt.io/post/230972</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Wed, 04 Jun 2014 15:11:14 GMT</pubDate></item><item><title><![CDATA[Reply to HasNext() returns true when the Qstring passed to QDirIterator is null on Tue, 03 Jun 2014 20:11:06 GMT]]></title><description><![CDATA[<p dir="auto">What is the "expected behavior" for iterating an <em>empty</em> string anyway? It's obviously <em>not</em> a valid directory, so what would you expert? The result probably is undefined. Or does it implicitly iterate the <em>current</em> directory ???</p>
<p dir="auto">(In the later case, the result depends on whatever happens to be your "current" directory - which is never a good idea)</p>
]]></description><link>https://forum.qt.io/post/230884</link><guid isPermaLink="true">https://forum.qt.io/post/230884</guid><dc:creator><![CDATA[MuldeR]]></dc:creator><pubDate>Tue, 03 Jun 2014 20:11:06 GMT</pubDate></item><item><title><![CDATA[Reply to HasNext() returns true when the Qstring passed to QDirIterator is null on Tue, 03 Jun 2014 19:54:21 GMT]]></title><description><![CDATA[<p dir="auto">Hi and welcome to devnet,</p>
<p dir="auto">Where does "QString((*itr).c_str())" come from ?</p>
<p dir="auto">I just tested with 4.8.6 replacing QString((*itr).c_str()) with QString("") and it does work as expected.</p>
]]></description><link>https://forum.qt.io/post/230881</link><guid isPermaLink="true">https://forum.qt.io/post/230881</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Tue, 03 Jun 2014 19:54:21 GMT</pubDate></item><item><title><![CDATA[Reply to HasNext() returns true when the Qstring passed to QDirIterator is null on Tue, 03 Jun 2014 17:43:58 GMT]]></title><description><![CDATA[<p dir="auto">Hi All</p>
<p dir="auto">In the end I coded a work around. I now check the Qstring and if it is empty then I do not call QDirIterator. What I really need to know is did I find a bug in 4.8.6 or a new feature?</p>
]]></description><link>https://forum.qt.io/post/230872</link><guid isPermaLink="true">https://forum.qt.io/post/230872</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Tue, 03 Jun 2014 17:43:58 GMT</pubDate></item></channel></rss>