Reputation: 4480
I am using below code to display chinese text on click of a button , its working fine in Windows but when i try in Embedded device it show some junk values. I am using "Batang" Font . This font is installed in my Embedded device.
QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());
QTextCodec::setCodecForTr(QTextCodec::codecForLocale());
QString qString1 = tr("鳶尾花");
QByteArray byteArray = qString1.toUtf8();
const char* cString = byteArray.data();
QString qString2 = QString::fromUtf8(cString);
QTextCodec::setCodecForTr(QTextCodec::codecForName(cString));
ui->txtFirstname->setText(qString2);
Any help is appreciated. Thanks
Upvotes: 1
Views: 2099
Reputation: 2742
Try using a different encoding and not UTF8 depends on the characters you will be using. Hope this helps.
Read this for more info: http://doc.qt.io/qt-5/codec-big5.html because the characters u use seem to be Big5 encoding characters A tutorial can be found here: http://doc.qt.io/qt-5/qtextcodec.html
Upvotes: 1
Reputation: 4480
I resolved using :
QTextCodec::setCodecForTr(QTextCodec::codecForName("GB18030"));
Big5 was not giving me correct result. Thanks.
Upvotes: 1
Reputation: 12600
When you added the line
QTextCodec::setCodecForTr(QTextCodec::codecForName(cString));
you probably thought the following overload:
QTextCodec * QTextCodec::codecForName ( const QByteArray & name ) [static]
would try to find the best codec for the characters in the byte array you supplied.
However, this function tries to find the codec which has a name closest to the value you supplied, so you would have to do something like
QTextCodec::setCodecForTr(QTextCodec::codecForName("Big5"));
instead.
Have you tried leaving out that line? You are already setting the text codec a few lines above anyway.
Upvotes: 1