PDA

View Full Version : Utf8 problems



cristiano
6th November 2006, 00:04
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

wysota
6th November 2006, 06:19
What database do you use? Are you sure it uses UTF-8 as the encoding?

cristiano
7th November 2006, 10:33
Hi,

Using PostgreSQL, and using UTF-8.

jacek
7th November 2006, 17:30
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.


textEdit3->setText(QString::fromUtf8(Test));
This actually corrupts the data.

cristiano
10th November 2006, 23:42
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

jacek
11th November 2006, 00:14
cbmCombo->insertItem(QString::fromUtf8(query.value( 0 ).toString()));
How about:
cbmCombo->insertItem( query.value( 0 ).toString() );?