Problems with Unicode(UTF8)
Hello,
I am with serious problems with Internacionalization (UNICODE) of characters in the Qt with the database PostgreSQL.
The data with caracters accented, appear wrong and also they are inserted in the DB of incorrect form.
I am running PosgreSQL on of the FreeBSD. Already I modified the configuration archive "postgresql.conf" for "client_encoding = utf8" more I did not get success.
I tried to create the base as UTF8 using,
$ createdb -E UTF8 foobase;
More simply when I create the base with UNICODE is shown the data for the Qt.
Re: Problems with Unicode(UTF8)
When Qt connects to PostgreSQL it sets the proper client encoding, so you don't have to worry about the database encoding --- it should work out of the box.
How do you retrieve strings from the database?
1 Attachment(s)
Re: Problems with Unicode(UTF8)
For example, selected the data in a QComboBox, the data appear incorrect.
QSqlQuery queryBairroLogradouro( "SELECT nm_bairro FROM bairros ORDER BY nm_bairro;" );
cmbBairroLogradouro->clear();
while ( queryBairroLogradouro.next() )
{
cmbBairroLogradouro->insertItem( queryBairroLogradouro.value( 0 ).toString() );
}
In form caracters appears as well as in the image in annex. Where the correct word would have to be in Portuguese “ANTENDIMENTO PRÉ-HOSPITALAR†with accent in the letter “Éâ€
Re: Problems with Unicode(UTF8)
Quote:
Originally Posted by
cristiano
For example, selected the data in a QComboBox, the data appear incorrect.
This looks OK. How do you put data into the database?
Re: Problems with Unicode(UTF8)
Jacek,
I use the (QSqlRecord*) to make insert in the database, the code is here:
http://200.193.29.195/trolltech/code1.h.html
The ui Form is here:
http://200.193.29.195/trolltech/gui.png
Re: Problems with Unicode(UTF8)
Quote:
QString Test = textEditDescricao->text();
textEditDescricao->setText(QString::fromUtf8(Test));
You shouldn't do this, except for that everything looks OK.
Does your application update records from "bairros" table? Maybe you should check whether data in the database is correctly encoded? Do you see correct characters if you start psql, issue "SET client_encoding TO '<encoding_used_by_your_system>';" and select something from that table?
Re: Problems with Unicode(UTF8)
In the terminal "KDE" of the system it correctly appears the data. it look register 4
footest=# select * from bairros;
id_bairro | id_cidade | nm_bairro | ch_repositorio
-----------+-----------+----------------+----------------
1 | 8105 | ESTREITO | S
2 | 8327 | PRAIA COMPRIDA | S
3 | 8105 | CENTRO | S
4 | 8105 | ATENÇÃO | S
(4 registros)
"ATENÇÃO" correct !
In Qt the characters appear wrong.
Re: Problems with Unicode(UTF8)
Quote:
Originally Posted by
cristiano
"ATENÇÃO" correct !
Did you use "SET client_encoding TO" to set the encoding explicitly?
Re: Problems with Unicode(UTF8)
For this in case that not, I am only using "setlocale" of "Shell" that he is configured for ptBR.
LC_ALL=pt_BR.ISO8859-1
Re: Problems with Unicode(UTF8)
Quote:
Originally Posted by
cristiano
For this in case that not, I am only using "setlocale" of "Shell" that he is configured for ptBR.
If you didn't set the encoding using SET client_encoding, then we still don't know if database contents is correctly encoded.
Alternatively you can try:
Quote:
footest=# show client_encoding;
footest=# select * from bairros;
If you see correct characters and client_encoding has the right value, then the database is OK.
Re: Problems with Unicode(UTF8)
This is returned,
footest=# show client_encoding;
client_encoding
-----------------
SQL_ASCII
(1 registro)
footest=# select * from bairros;
id_bairro | id_cidade | nm_bairro | ch_repositorio
-----------+-----------+----------------+----------------
1 | 8105 | ESTREITO | S
2 | 8327 | PRAIA COMPRIDA | S
3 | 8105 | CENTRO | S
4 | 8105 | ATENÇÃO | S
(4 registros)
Re: Problems with Unicode(UTF8)
OK and what happens when you execute this?
Quote:
footest=# set client_encoding to 'latin1';
footest=# select * from bairros;
Re: Problems with Unicode(UTF8)
footest=# set client_encoding to 'latin1';
SET
footest=# select * from bairros;
id_bairro | id_cidade | nm_bairro | ch_repositorio
-----------+-----------+----------------+----------------
1 | 8105 | ESTREITO | S
2 | 8327 | PRAIA COMPRIDA | S
3 | 8105 | CENTRO | S
4 | 8105 | ATENÇÃO | S
(4 registros)
footest=# show client_encoding;
client_encoding
-----------------
latin1
(1 registro)
As 'latin1' the data is shown correctly, more in the continuous application with the incorrect characters.
Re: Problems with Unicode(UTF8)
Hmm... everything looks OK. Does the database protest if you issue:
Quote:
SET client_encoding TO 'UNICODE';
?
Re: Problems with Unicode(UTF8)
SET client_encoding TO 'UNICODE';
SET
footest=# select * from bairros;
id_bairro | id_cidade | nm_bairro | ch_repositorio
-----------+-----------+----------------+----------------
1 | 8105 | ESTREITO | S
2 | 8327 | PRAIA COMPRIDA | S
3 | 8105 | CENTRO | S
4 | 8105 | ATENO | S
(4 registros)
The data come incorrect, already I am losing the hope for this.
Re: Problems with Unicode(UTF8)
Quote:
Originally Posted by
cristiano
SET client_encoding TO 'UNICODE';
SET
OK, so IMO there shouldn't be any problem with the database.
What does this program output?
Code:
#include <QCoreApplication>
#include <QTextCodec>
#include <QtDebug>
int main( int argc, char ** argv )
{
}
Do you use QString::fromUtf8(), QString::toUtf8() and similar methods in your program?
Do you use any static or global variables that have something to do with the database handling?
Quote:
Originally Posted by
cristiano
The data come incorrect
It doesn't matter, the most important part is that PostgreSQL wants to talk with you in Unicode.