Results 1 to 16 of 16

Thread: Problems with Unicode(UTF8)

  1. #1
    Join Date
    Sep 2006
    Posts
    42
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Unhappy 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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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?

  3. #3
    Join Date
    Sep 2006
    Posts
    42
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Unhappy 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 “É”
    Attached Images Attached Images

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems with Unicode(UTF8)

    Quote Originally Posted by cristiano View Post
    For example, selected the data in a QComboBox, the data appear incorrect.
    This looks OK. How do you put data into the database?

  5. #5
    Join Date
    Sep 2006
    Posts
    42
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Unhappy 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

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems with Unicode(UTF8)

    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?

  7. #7
    Join Date
    Sep 2006
    Posts
    42
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default 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.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems with Unicode(UTF8)

    Quote Originally Posted by cristiano View Post
    "ATENÇÃO" correct !
    Did you use "SET client_encoding TO" to set the encoding explicitly?

  9. #9
    Join Date
    Sep 2006
    Posts
    42
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default 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

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems with Unicode(UTF8)

    Quote Originally Posted by cristiano View Post
    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:
    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.

  11. #11
    Join Date
    Sep 2006
    Posts
    42
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default 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)

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems with Unicode(UTF8)

    OK and what happens when you execute this?
    footest=# set client_encoding to 'latin1';
    footest=# select * from bairros;

  13. #13
    Join Date
    Sep 2006
    Posts
    42
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default 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.

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems with Unicode(UTF8)

    Hmm... everything looks OK. Does the database protest if you issue:
    SET client_encoding TO 'UNICODE';
    ?

  15. #15
    Join Date
    Sep 2006
    Posts
    42
    Thanks
    2
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default 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.

  16. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems with Unicode(UTF8)

    Quote Originally Posted by cristiano View Post
    SET client_encoding TO 'UNICODE';
    SET
    OK, so IMO there shouldn't be any problem with the database.

    What does this program output?
    Qt Code:
    1. #include <QCoreApplication>
    2. #include <QTextCodec>
    3.  
    4. #include <QtDebug>
    5.  
    6. int main( int argc, char ** argv )
    7. {
    8. QCoreApplication app( argc, argv );
    9. qDebug() << QTextCodec::codecForLocale()->name();
    10. }
    To copy to clipboard, switch view to plain text mode 

    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 View Post
    The data come incorrect
    It doesn't matter, the most important part is that PostgreSQL wants to talk with you in Unicode.

Similar Threads

  1. Problems
    By euthymos in forum Installation and Deployment
    Replies: 2
    Last Post: 13th June 2006, 19:11
  2. Canvas problems
    By Tommytrojan in forum Qt Programming
    Replies: 22
    Last Post: 9th May 2006, 16:46
  3. QT4 Plugins - problems, problems
    By NormanDunbar in forum Qt Programming
    Replies: 6
    Last Post: 9th May 2006, 15:39
  4. [Win32/VC++ 8.0] Strange problems with qrc_*.cpp files
    By mloskot in forum Installation and Deployment
    Replies: 6
    Last Post: 6th March 2006, 10:28
  5. problems with Opengl
    By SlawQ in forum Qt Programming
    Replies: 4
    Last Post: 12th February 2006, 22:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.