Results 1 to 16 of 16

Thread: Problems with Unicode(UTF8)

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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)

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
  •  
Qt is a trademark of The Qt Company.