Results 1 to 6 of 6

Thread: Utf8 problems

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

    Default Utf8 problems

    Hi all,

    I am having problems in converting QStrings default for Utf8, and the data typed for the users are entering with defect in database.

    The language of the application is in (Brazil Portuguese).

    Already I made some attempts without success more, as for example.

    /********* Foo Test **********/
    QTextCodec::setCodecForLocale ( QTextCodec::codecForName ( "UTF-8" ) );
    QTextCodec::setCodecForCStrings ( QTextCodec::codecForName ( "UTF-8" );

    QString Test = textEdit3->text();
    textEdit3->setText(QString::fromUtf8(Test));
    /*******************************/

    Some idea of as I can transform this.

    Cristiano

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Utf8 problems

    What database do you use? Are you sure it uses UTF-8 as the encoding?

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

    Default Re: Utf8 problems

    Hi,

    Using PostgreSQL, and using UTF-8.

  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: Utf8 problems

    Quote Originally Posted by cristiano View Post
    Using PostgreSQL, and using UTF-8.
    You don't have to do anything to store strings correctly in PostgreSQL, as Qt sets "client_encoding" to Unicode when it connects to PostgreSQL and it stores QString data in Unicode, so the only thing you must worry about is to assign data to QStrings correctly.

    Quote Originally Posted by cristiano View Post
    textEdit3->setText(QString::fromUtf8(Test));
    This actually corrupts the data.

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

    Angry Re: Utf8 problems

    I also face problems with the QComBox to list the data, the words appear with strange characters, example:

    Word of the type in Portuguese Brazil “comunicação”

    QString command = QString::fromUtf8("SELECT table FROM unicode ORDER BY unicode;");
    QSqlQuery query(command);

    while ( query.next() )
    {
    cbmCombo->insertItem(QString::fromUtf8(query.value( 0 ).toString()));
    }

    Cristiano

  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: Utf8 problems

    Quote Originally Posted by cristiano View Post
    cbmCombo->insertItem(QString::fromUtf8(query.value( 0 ).toString()));
    How about:
    Qt Code:
    1. cbmCombo->insertItem( query.value( 0 ).toString() );
    To copy to clipboard, switch view to plain text mode 
    ?

Similar Threads

  1. QGLWidget Problems
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 2nd October 2006, 22:06
  2. Problems
    By euthymos in forum Installation and Deployment
    Replies: 2
    Last Post: 13th June 2006, 19:11
  3. Detect utf8 text/html bool....
    By patrik08 in forum Newbie
    Replies: 2
    Last Post: 2nd June 2006, 11:39
  4. Problems building mysql plugin for Qt 4.1.2 on windows XP
    By Philip_Anselmo in forum Installation and Deployment
    Replies: 3
    Last Post: 17th May 2006, 15:38
  5. QT4 Plugins - problems, problems
    By NormanDunbar in forum Qt Programming
    Replies: 6
    Last Post: 9th May 2006, 15:39

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.