<?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[Problem with QSqlField.type() (when used with QSqlTableModel)]]></title><description><![CDATA[<p dir="auto">I'm trying to determine the datatype of the columns (fields) of a PostgreSQL database table as rendered by QSqlTableModel. I'm using QSqlField.type() for this:</p>
<p dir="auto">("model" is a QSqlTableModel)<br />
@<br />
QSqlRecord rec = model-&gt;record(1);<br />
QSqlField f = rec.field("name");<br />
QVariant v = f.value();<br />
qDebug() &lt;&lt; "Field Value for row 0 and column 1/name (should be Alex)" &lt;&lt; v.toString();<br />
QSqlField f2 = rec.field("name");<br />
QVariant t = f2.type();<br />
qDebug() &lt;&lt; "Field Type for column 1/name (should be char)" &lt;&lt; t.toString();<br />
QSqlField f3 = rec.field("id");<br />
t = f3.type();<br />
qDebug() &lt;&lt; "Field Type for column 0/id (should be int)" &lt;&lt; t.toString();<br />
@</p>
<p dir="auto">Unfortunately, this is what I get from the code above:</p>
<p dir="auto">@<br />
Field Value for row 0 and column 1/name (should be Alex) "Alex"<br />
Field Type for column 1/name (should be char) ""<br />
Field Type for column 0/id (should be int) "0"<br />
@</p>
<p dir="auto">Does anybody know what is going wrong here?</p>
<p dir="auto">Thanks</p>
]]></description><link>https://forum.qt.io/topic/14062/problem-with-qsqlfield-type-when-used-with-qsqltablemodel</link><generator>RSS for Node</generator><lastBuildDate>Mon, 10 Aug 2026 23:34:30 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/14062.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 14 Feb 2012 20:38:52 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Problem with QSqlField.type() (when used with QSqlTableModel) on Wed, 15 Feb 2012 09:13:53 GMT]]></title><description><![CDATA[<p dir="auto">QVariant::Type is an enum (int) type</p>
]]></description><link>https://forum.qt.io/post/129095</link><guid isPermaLink="true">https://forum.qt.io/post/129095</guid><dc:creator><![CDATA[foxyz]]></dc:creator><pubDate>Wed, 15 Feb 2012 09:13:53 GMT</pubDate></item><item><title><![CDATA[Reply to Problem with QSqlField.type() (when used with QSqlTableModel) on Wed, 15 Feb 2012 07:29:51 GMT]]></title><description><![CDATA[<p dir="auto">Thanks! Now it works as expected:</p>
<p dir="auto">@<br />
Field Value for row 1 and column 1 (should be Alex) "Alex"<br />
Field Type for column 1/name (should be char) QVariant::QString<br />
Field Type for column 0/id (should be int) QVariant::int<br />
@</p>
<p dir="auto">BTW, the qDebug line should be like this:</p>
<p dir="auto">@<br />
qDebug() &lt;&lt; "Field Type for column 1/name (should be char)" &lt;&lt; t;<br />
@</p>
<p dir="auto">(No .toString() casting)</p>
]]></description><link>https://forum.qt.io/post/129072</link><guid isPermaLink="true">https://forum.qt.io/post/129072</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Wed, 15 Feb 2012 07:29:51 GMT</pubDate></item><item><title><![CDATA[Reply to Problem with QSqlField.type() (when used with QSqlTableModel) on Tue, 14 Feb 2012 20:55:56 GMT]]></title><description><![CDATA[<p dir="auto">This is wrong:</p>
<p dir="auto">@<br />
QVariant t = f2.type();<br />
@</p>
<p dir="auto">"QSqlField::type() ":/doc/qt-4.8/qsqlfield.html#type returns a QVariant::Type, not a QVariant!</p>
<p dir="auto">Change your code to this:</p>
<p dir="auto">@<br />
QVariant::Type t = f2.type();<br />
@</p>
<p dir="auto">The qDebug() output should print 10, which is QVariant::String.</p>
]]></description><link>https://forum.qt.io/post/129031</link><guid isPermaLink="true">https://forum.qt.io/post/129031</guid><dc:creator><![CDATA[[[global:former-user]]]]></dc:creator><pubDate>Tue, 14 Feb 2012 20:55:56 GMT</pubDate></item></channel></rss>