<?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[QSqlQuery: remove a record]]></title><description><![CDATA[<p dir="auto">I tried removing some records from QSqlQuery using <em>query.record().remove(pos)</em> but it doesn't work at all. Is there any way to remove the record from QSqlQuery? I know about QSqlQueryModel, but I would like to use QSqlQuery, because it works fine for my application.<br />
@<br />
#include "QtSql/QtSql"<br />
#include "QtSql/QSqlRecord"</p>
<p dir="auto">QString sql_str;<br />
sql_str =  "select * from param";<br />
QSqlQuery query;<br />
query.prepare(sql_str);<br />
query.exec();</p>
<p dir="auto">int index=0;</p>
<p dir="auto">query.seek(-1);</p>
<pre><code>while(query.next()){
    query.record().clear();
    query.record().clearValues();
    query.record().remove(0);
    ui-&gt;tableWidget_2-&gt;setItem(index,0,new QTableWidgetItem(query.record().value(0).toString()));
    ui-&gt;tableWidget_2-&gt;setItem(index,1,new QTableWidgetItem(query.value(1).toString()));
    index++;
}@
</code></pre>
]]></description><link>https://forum.qt.io/topic/41442/qsqlquery-remove-a-record</link><generator>RSS for Node</generator><lastBuildDate>Thu, 07 May 2026 10:26:49 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/41442.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 15 May 2014 12:24:02 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QSqlQuery: remove a record on Thu, 15 May 2014 18:58:43 GMT]]></title><description><![CDATA[<p dir="auto">Thanks for replies, but I don't want to delete stuff from my database.<br />
Actually, I need to remove records from my query and don't touch database. I'd like to organize somewhat like filter on the program level not database level.<br />
I've already got all data in my query and I think it's irrational to execute the query to the database each time.</p>
]]></description><link>https://forum.qt.io/post/228658</link><guid isPermaLink="true">https://forum.qt.io/post/228658</guid><dc:creator><![CDATA[Evgenij1]]></dc:creator><pubDate>Thu, 15 May 2014 18:58:43 GMT</pubDate></item><item><title><![CDATA[Reply to QSqlQuery: remove a record on Thu, 15 May 2014 18:04:17 GMT]]></title><description><![CDATA[<p dir="auto">Here is an example on how to use the exec.</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bool">@<bdi>bool</bdi></a> TickedgeDatabase::deleteModel(int modelID)<br />
{<br />
bool   bstatus = false;<br />
QString filter;<br />
QString str;<br />
if (!handle) {<br />
errorMessage = tr("delete  Mode  - handle is not initialized");<br />
qWarning() &lt;&lt; errorMessage;<br />
return false;<br />
}</p>
<p dir="auto">QSqlQuery query(*handle);<br />
filter = "modelID='" + QString::number(modelID) + "'";<br />
str  = "delete from models where " + filter;<br />
bstatus = query.prepare(str);<br />
if (bstatus == false) {<br />
qWarning() &lt;&lt; "Delete from model table  failed in prepare " &lt;&lt; <strong>FILE</strong> &lt;&lt; <strong>LINE</strong>;<br />
sqlError = query.lastError();<br />
goto done;<br />
}<br />
bstatus = query.exec();<br />
if (bstatus == false) {<br />
sqlError = query.lastError();<br />
errorMessage = sqlError.databaseText();<br />
qWarning() &lt;&lt; errorMessage;<br />
}<br />
done:<br />
return bstatus;<br />
@</p>
]]></description><link>https://forum.qt.io/post/228652</link><guid isPermaLink="true">https://forum.qt.io/post/228652</guid><dc:creator><![CDATA[DBoosalis]]></dc:creator><pubDate>Thu, 15 May 2014 18:04:17 GMT</pubDate></item><item><title><![CDATA[Reply to QSqlQuery: remove a record on Thu, 15 May 2014 14:59:38 GMT]]></title><description><![CDATA[<p dir="auto">Hi, QSqlRecord::remove() doesn't remove any records from the database or from your query (it just removes a field from the record).</p>
<p dir="auto">If you want to delete stuff from your database you can use QSqlQuery::exec().</p>
]]></description><link>https://forum.qt.io/post/228637</link><guid isPermaLink="true">https://forum.qt.io/post/228637</guid><dc:creator><![CDATA[hskoglund]]></dc:creator><pubDate>Thu, 15 May 2014 14:59:38 GMT</pubDate></item></channel></rss>