Hi Lisandro,

AFAIK that is a bug in the design of the Qt SQL api's.  There is no way to specify to QSqlField/QSqlResult that the date being read is UTC.  You have to read the QSqlQuery yourself, convert the QVariant to QDateTime, apply the time spec, then pass the value to the UI.

Maybe you can derive from QSqlRelationalTableModel and override the data method to set the time spec?

Regards, Tony


On 1/05/2020 5:04 am, Lisandro Damián Nicanor Pérez Meyer wrote:
Hi!

I have a database (PostgreSql) with a table that holds date/time in
UTC. I've read this table with the QSqlRelationalTableModel and show
the data with a QTableView and a QDateTimeEdit.

I would like both the QTableView and the QDateEdit to show the time in
local timezone, but I seem to be failing at this.

I have tried with
ui->admissionDateTimeEdit->setTimeSpec(Qt::OffsetFromUTC) and other
time specs both before and after setting the model without success
(there is a bug for that in [1])

Is there something else I am missing?

The actual code is in [2] but it's not minimal. If needed I'll try to
get a minimal example for this.

[1] <https://bugreports.qt.io/browse/QTBUG-54781>
[2] 
<https://gitlab.com/mosimpa/abm/-/blob/feature/manage-internments/src/internmentsform.cpp>

Thanks in advance!

_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to