PDA

View Full Version : Khmer Unicode Problem with Qt 4.7/QTextEdit



lsvichet
23rd May 2011, 11:34
Hi all,

I have a problem displaying Khmer Unicode Character on QTextEdit. While other Khmer Unicode Character shown correctly in QTextEdit, this special case as shown in the figure below, did not show as expected. The same text in Ms Word show correctly what it is expected.

I typed the text directly into QTextEdit field.

http://dahlina.com/wordpress/wp-content/uploads/2011/05/unicode-qt.jpg

Here is my code:


#include <QApplication>
#include <QTextEdit>

int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QTextEdit txt;
QFont font;
font.setPointSize(18);
txt.setFont(font);
txt.show();

return app.exec();
}

Thanks for any kind reply.

tinysoft
23rd May 2011, 13:46
try to use this :



#include <QTextCodec>
QTextCodec::setCodecForCStrings(QTextCodec::codecF orName("UTF-8"));

lsvichet
23rd May 2011, 16:00
Thanks Tinysoft for your fast reply. I have change the code to sth like:


QTextCodec::setCodecForCStrings(QTextCodec::codecF orName("UTF-8"));
QTextEdit txt;
QFont font;
font.setPointSize(18);
txt.setFont(font);

But it still doesn't work.

tinysoft
23rd May 2011, 19:22
try to replace the "UTF-8" wih one of the other unicodes >> see here (http://doc.qt.nokia.com/latest/qtextcodec.html)

this link (http://en.wikipedia.org/wiki/Khmer_script) might help you to choose the correct Unicode.

good luck !

lsvichet
23rd May 2011, 20:34
The correct codec for Khmer Unicode is UTF8. I just found that I have the same problem when typing the same text in Text Editor of Ubuntu. Perhap this is not QT problem.

Anyway thanks for your suggestion.