PDA

View Full Version : Problem with QTableView, or QSqlTableModel, postgresql and locale



zygmunt
21st December 2009, 21:14
Hi!
My locale is pl_PL.
I have problem with QTableView and postgresql database.
Double values is represented by integer.
I set names in postgres by: set names 'latin2'.
When i write some double 1.09 in QTableView i see as 1
but in psql is 1.09. How can i set type in model or tableview to float or double for some columns??

I overload in QSqlTableModel method:
QVariant QSqlTableModel::data(const QModelIndex & i, int role ) const
and show QVariant for special column. But i still get integer.

I forgot, my base table isn't table but perspective.

tangential
22nd December 2009, 03:57
This looks like a locale issue, if you set the QSqlQuery::setNumericalPrecisionPolicy to QSql::HighPrecision, does it give you the correct value? (Maybe with . instead of ,? or , instead of .?). I'm not sure how to fix the issue from there tho, maybe QLocale::setDefault?

Lesiok
22nd December 2009, 07:09
In pl_PL locale decimal separator is , not .

zygmunt
22nd December 2009, 12:18
@tangential
ok, but this method is in qt4.6 ;-/ (i have 4.5.3 in arch linux, and i don't want recompile qt)
@lesiok
i know

How to set in qlocale decimalPoint??

zygmunt
22nd December 2009, 14:39
On Qt-4.6.0 from default settings works fine;-)
Thanks.

tangential
23rd December 2009, 01:53
On Qt-4.6.0 from default settings works fine;-)
Thanks.

Heh, could be something I fixed in between 4.5.3 and 4.6. There's been a lot of bugfixing work done, starting from 4.5.0

Re the setPrecisionPolicy, that should be there in the result from a long time ago, 4.6 only surfaced it to the database as well as the query (and takes the default from the db setting).

That said, it's good to see it's working for you :)