I'm developing a Qt GUI application to parse out a custom windows binary file that stores unicode text using wchar_t (default UTF-16 encoding). I've constructed a QString
using QString::fromWcharArray
and passed it to QTextBrowser::insertPlainText
like this
wchar_t *p = ; // pointer to a wchar_t string in the binary file
QString t = QString::fromWCharArray(p);
ui.logBrowser->insertPlainText(t);
The displayed text displays ASCII characters correctly, but non-ASCII characters are displayed as a rectangular box instead. I've followed the code in a debugger and p
points to a valid wchar_t string and the constructed QString t
is also a valid string matching the wchar_t string. The problem happens when printing it out on a QTextBrowser
.
How do I fix this?
First of all read documentation. So depending on system you will have different encoding UCS-4
or UTF-16
! What is the size of wchar_t
?
Secondly there is alternative API: try QString::fromUtf16.
Finally what kind of character are you using? Hebrew/Cyrillic/Japanese/???. Are you sure those characters are supported by font you are using?