PDA

View Full Version : Get Korean string from MYSQL(KUBUNTU)



morgana
4th July 2008, 17:45
Hello. I'm newbie on QT.

I'm sorry for my english.

I want to display MessageBox that include Korean string(from MYSQL).

Numeric with Alphabet is well done. Only Korean string is broken display.

The Code is like it.
-------------------------------------

QSqlQuery *query= new QSqlQuery("select Name from User where id='"+id+"' and password='"+password+"'"); //set query
//Name is Korean String char(12)

query->exec();
query->next();

QString temp1;
temp1=query->value(0).toString(); // this step need not convert encoding????

QByteArray temp=temp1.toLocale8Bit();
char *string=temp.data();
QMessageBox::information(this, "Information", QString::fromUtf8(string), QMessageBox::Ok);

jpn
6th July 2008, 19:57
What's the encoding of the string in database? What does

QMessageBox::information(this, "Information", temp1, QMessageBox::Ok);
show?

morgana
7th July 2008, 07:57
What's the encoding of the string in database? What does

QMessageBox::information(this, "Information", temp1, QMessageBox::Ok);
show?
I solved.
The cause is MYSQL encoding.
I got information MYSQL encoding set by latin.(show variables like 'c%')
Korean is not latin.
1. So i changed encoding latin to UTF8(edit my.cnf)
2. And table character set change UTF8.
Alternative: CREATE DATABASE [db_name] DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

thanks to interesting.

Have a nice dream.