PDA

View Full Version : messed up umlauts when reading from PostgreSQL



majorwoody
20th January 2011, 10:42
Hi there,

I'm trying to connect to a Postgres database and read some rows with QSqlQueryModel
When I open the standard connection with

QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL");
QSqlQueryModel m;
m.setQuery("select task_id, name, project_id, recurrence from task");

everything works fine.

Now when I open the connection with an alternative connection name

QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL", QLatin1String("Main"));
QSqlQueryModel m;
m.setQuery("select task_id, name, project_id, recurrence from task", QSqlDatabase::database(QLatin1String("Main")));

the data in field name is not shown correctly. All german umlauts are not correct.

Why is the encoding for the standard connection different from an alternative connection? How can I set the correct encoding?

Thanks in advance
Andreas

majorwoody
20th January 2011, 20:37
I found out, that using alternative connection works pretty good, when a default connection exists. So my suggestion is to always open the default connection and then open connections with other names.

Still there is the question, what is the difference between calling addDatabase with and without the second parameter and why does it behave different?