[SOLVED] QSqlTableView translation of MySQL TINYINT(1) type
In MySQL the Boolean type is synonomous with the TINYINT (1) type.
When a query returns rows with a column of this type, the Qt SQL framework translates it to a QVariant::Int type (or potentially QVariant:Unsigned, see QTBUG-14073).
This is then displayed by a QSqlTableView as "0" or "1".
Typically, if this column was designed to represent a boolean value, a checkbox widget would be used to edit the column. E.g. via direct in-table editing, or via QDataWidgetMapper.
However, after editing, the "user" property of the checkbox widget will set the column back as QVariant::Bool. This will then show up in the table as "true" or "false".
Ideally, I would prefer to always see the value as "true" or "false". Is there a way to ensure the initial table query appears this way? I.e. treats the TINYINT (of size 1) as boolean.
Hi and welcome to devnet,
You could use a QIdentityProxyModel and return true or false based on the content of the database for this column.
Hope it helps
Thanks, that's exactly what I was looking for.
You're welcome !
Since you have your view running, please update the thread title preening [solved] so other forum users may know a solution has been found :)