PDA

View Full Version : Qstring conversion containing japanese character's to const char *.



vaibhav
7th September 2011, 17:02
Hi ,
I store the Japanese character in QString.
Now i want to convert QString to const Char * .
When i do so using qPrintable my const char * pointer points to some garbage value like "??".
How to convert QString to const char * which contains Japanese charater.

Thanks.

wysota
7th September 2011, 17:09
qPrintable() uses latin1 encoding. Japanese characters won't fit in there. You need to use proper encoding.

vaibhav
7th September 2011, 18:56
Could you please suggest some code for the correct encoding .

wysota
7th September 2011, 18:58
http://en.wikipedia.org/wiki/Japanese_language_and_computers#Character_encoding s
QTextCodec

vaibhav
8th September 2011, 10:03
I tried using QTextCodec .But it didn't worked :(

QString stringName; //Normal English String to be converted into Japanese .

QString strTitle=QApplication::translate("Window", stringName.toUtf8().data() , 0 , QCoreApplication::UnicodeUTF8 ); //Returns Japanese Charater properly

QTextCodec *codec = QTextCodec::codecForName("UTF-8");
QByteArray byteString = codec->fromUnicode(strTitle);


I want const char * pointer pointing to this japanese string so i converted it to byteArray.
But here byteString doesn't contain proper japanese character .


I am using UTF-8 encoding as it solve all encoding problems in all languages of the world.

Let me know about my approach.
Thanks.

wysota
8th September 2011, 11:38
You can't put utf-8 encoded strings in char*. I suggest you first learn what encoding are, why we use them and what each of them looks like before you try to solve your problem. Don't just blindly try things you don't understand.