<?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[QT SQL query loop?]]></title><description><![CDATA[<p dir="auto">Hey, currently this loop only gets the first username in the table, how can i properly do this so it checks all rows for the username<br />
while (query.next() &amp;&amp; query.value("Username").toString().toUtf8().constData() &amp;&amp; query.value("Password").toString().toUtf8().constData())<br />
{<br />
printf("Usernames: %s", query.value("Username").toString().toUtf8().constData());</p>
]]></description><link>https://forum.qt.io/topic/93603/qt-sql-query-loop</link><generator>RSS for Node</generator><lastBuildDate>Wed, 22 Apr 2026 13:53:21 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/93603.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 11 Aug 2018 17:29:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QT SQL query loop? on Sun, 12 Aug 2018 15:42:04 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/davethedave">@<bdi>davethedave</bdi></a><br />
Firstly, I don't work in C++ so I don't test the code for the right way to pass the output string to <code>printf()</code>.  So your corrections are good.  [BTW you'd be better off not using <code>printf()</code> and using Qt/C++ functions, then you wouldn't have all that <code>toUtf8().constData()</code> stuff, but that's another matter.]</p>
<p dir="auto">As you can see you have 3 rows matching the query, you tell us you have 5, or you had 5 and now you have 3.  That's worrying when you're asking for help.  Your <code>Username</code> value appears to be <code>1</code> from the output.  That is a strange username.   I don't know what your problem is.  The original code should correctly print out whatever is in the <code>Username</code> column of each row encountered (note that since you didn't put a <code>\n</code> in it will all come on one line, which isn't great, I do trust that is not what this is all about.)</p>
]]></description><link>https://forum.qt.io/post/475615</link><guid isPermaLink="true">https://forum.qt.io/post/475615</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sun, 12 Aug 2018 15:42:04 GMT</pubDate></item><item><title><![CDATA[Reply to QT SQL query loop? on Sun, 12 Aug 2018 15:25:18 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> said in <a href="/post/475611">QT SQL query loop?</a>:</p>
<blockquote>
<p dir="auto">query.exec("SELECT * FROM users");</p>
</blockquote>
<p dir="auto">from the first:<br />
<a href="http://prntscr.com/khp72u" target="_blank" rel="noopener noreferrer nofollow ugc">http://prntscr.com/khp72u</a></p>
<p dir="auto">if i append<br />
.toUtf8().constData() then the below<br />
<a href="http://prntscr.com/khp79y" target="_blank" rel="noopener noreferrer nofollow ugc">http://prntscr.com/khp79y</a></p>
<p dir="auto">from the second:<br />
<a href="http://prntscr.com/khp72u" target="_blank" rel="noopener noreferrer nofollow ugc">http://prntscr.com/khp72u</a></p>
<p dir="auto">if i append<br />
.toUtf8().constData() then the below<br />
<a href="http://prntscr.com/khp7tw" target="_blank" rel="noopener noreferrer nofollow ugc">http://prntscr.com/khp7tw</a></p>
<p dir="auto">Also there is only 3 rows now</p>
]]></description><link>https://forum.qt.io/post/475613</link><guid isPermaLink="true">https://forum.qt.io/post/475613</guid><dc:creator><![CDATA[davethedave]]></dc:creator><pubDate>Sun, 12 Aug 2018 15:25:18 GMT</pubDate></item><item><title><![CDATA[Reply to QT SQL query loop? on Sun, 12 Aug 2018 15:13:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/davethedave">@<bdi>davethedave</bdi></a><br />
Please show output of each of the 2 following:</p>
<pre><code>query.exec("SELECT COUNT(*) FROM users");
while (query.next())
{
    printf("Number: %s\n", query.value(0).toString());
}
</code></pre>
<pre><code>query.exec("SELECT * FROM users");
while (query.next())
{
    printf("Username: %s\n", query.value(0).toString());
}
</code></pre>
]]></description><link>https://forum.qt.io/post/475611</link><guid isPermaLink="true">https://forum.qt.io/post/475611</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sun, 12 Aug 2018 15:13:35 GMT</pubDate></item><item><title><![CDATA[Reply to QT SQL query loop? on Sun, 12 Aug 2018 11:56:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a><br />
Prints first entry in the table still.</p>
]]></description><link>https://forum.qt.io/post/475599</link><guid isPermaLink="true">https://forum.qt.io/post/475599</guid><dc:creator><![CDATA[davethedave]]></dc:creator><pubDate>Sun, 12 Aug 2018 11:56:29 GMT</pubDate></item><item><title><![CDATA[Reply to QT SQL query loop? on Sun, 12 Aug 2018 10:35:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/davethedave">@<bdi>davethedave</bdi></a></p>
<pre><code>query.exec("SELECT * FROM users");
while (query.next())
{
    printf("Usernames: %s", query.value("Username").toString());
}
</code></pre>
]]></description><link>https://forum.qt.io/post/475587</link><guid isPermaLink="true">https://forum.qt.io/post/475587</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sun, 12 Aug 2018 10:35:27 GMT</pubDate></item><item><title><![CDATA[Reply to QT SQL query loop? on Sun, 12 Aug 2018 10:32:53 GMT]]></title><description><![CDATA[<p dir="auto">Hello, I have 5 entries<br />
query.exec("SELECT * FROM users");<br />
if (query.size() &gt; 0)</p>
<p dir="auto">and its the only check i could think of</p>
]]></description><link>https://forum.qt.io/post/475585</link><guid isPermaLink="true">https://forum.qt.io/post/475585</guid><dc:creator><![CDATA[davethedave]]></dc:creator><pubDate>Sun, 12 Aug 2018 10:32:53 GMT</pubDate></item><item><title><![CDATA[Reply to QT SQL query loop? on Sat, 11 Aug 2018 18:50:44 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">How many entries do you have in that table ?<br />
What query did you use ?<br />
Why are you doing this complex check in the while condition ?</p>
]]></description><link>https://forum.qt.io/post/475514</link><guid isPermaLink="true">https://forum.qt.io/post/475514</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Sat, 11 Aug 2018 18:50:44 GMT</pubDate></item></channel></rss>