<?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[[SOLVED] Is a QSqlQueryModel the proper way to bind a table&#x27;s field to a QListView?]]></title><description><![CDATA[<p dir="auto">I have a db table with two fields: id and keyword</p>
<p dir="auto">I wanted to display keyword in a QListView but was getting the id value, since that is the first field in the table. I ended up using a QSqlQueryModel and it works but I'm wondering if this is the standard way of doing this.</p>
<p dir="auto">The user will be able to add additional keywords to the db, so in order to display the new data I need to do a new query. I tried switching to a QTableView  and QSQLTableModel but I don't need that functionality. Bad decision?</p>
<p dir="auto">I'm setting up the QSqlQueryModel &gt; QListView connection as follows.<br />
@<br />
model = new QSqlQueryModel(this);<br />
model-&gt;setQuery("SELECT keyword FROM keywords",db);<br />
keywordListView-&gt;setModel(model);<br />
@</p>
]]></description><link>https://forum.qt.io/topic/30342/solved-is-a-qsqlquerymodel-the-proper-way-to-bind-a-table-s-field-to-a-qlistview</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Apr 2026 03:13:24 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/30342.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 05 Aug 2013 23:51:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [SOLVED] Is a QSqlQueryModel the proper way to bind a table&#x27;s field to a QListView? on Tue, 06 Aug 2013 02:53:56 GMT]]></title><description><![CDATA[<p dir="auto">Hey thanks! I'd missed _ setModelColumn()._</p>
]]></description><link>https://forum.qt.io/post/189619</link><guid isPermaLink="true">https://forum.qt.io/post/189619</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Tue, 06 Aug 2013 02:53:56 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] Is a QSqlQueryModel the proper way to bind a table&#x27;s field to a QListView? on Tue, 06 Aug 2013 01:36:51 GMT]]></title><description><![CDATA[<p dir="auto">You can use the table model with a list view by setting the column that is displayed: QListView::setModelColumn().</p>
<p dir="auto">QSqlQueryModel is read-only.   If you want to update through the model then you need to use QSqlTableModel (or your own custom model).<br />
You will need to address how the undisplayed column gets a value when new rows are added.</p>
]]></description><link>https://forum.qt.io/post/189614</link><guid isPermaLink="true">https://forum.qt.io/post/189614</guid><dc:creator><![CDATA[ChrisW67]]></dc:creator><pubDate>Tue, 06 Aug 2013 01:36:51 GMT</pubDate></item></channel></rss>