PDA

View Full Version : Japanese character read from html file and show in QTextEdit



santosh.kumar
30th December 2016, 05:09
Hi

I am using Qt 4.8.7 on Windows. I have one Japanese HTML file, I have to read it using QTextStream's readAll() and display it into QTextEdit. But it show Garbage character and not actual Japanese character...

QFile file(FilePath);
file.open(QFile::ReadOnly | QFile::Text);

QTextStream in(&file);
QString strData = in.readAll();

m_pTextEdit->setText(strData);

But it show garbage character.. What am I doing wrong.

Thanks
Santosh

CAFFRY
30th December 2016, 08:39
whatever u have done is wrong ..retry once again..add certain library fucntion and get into it..

refer this'

doc.qt.io/qt-5/qtexamplesandtutorials.html

anda_skoa
30th December 2016, 10:25
But it show garbage character.. What am I doing wrong.


First thing you should try is calling QTextEdit::setHtml() instead of setText() if the content is HTML.

Second, check that your file is encoded in UTF-8 or set a different codec on the QTextStream.

Cheers,
_