1

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?

shebaw
  • 1,775
  • 1
  • 13
  • 15
  • 1
    Duplicate of this question http://stackoverflow.com/questions/28495855/why-unicode-fonts-are-not-showing-properly-in-the-qtextbrowser-when-unicode-cont ? – rpsml May 28 '15 at 11:12
  • @rpsml, I checked that before asking. In his case, I think the issue has to do with reading the file with correct encoding. In my case, I'm operating on a memory mapped file and the generate QString actually is correct when checking it under a debugger. Posting it on a QTextBrowser is where the problem is. – shebaw May 28 '15 at 11:18
  • 1
    What font are you using? Does the font support the required characters? – Frank Osterfeld May 28 '15 at 11:35
  • @FrankOsterfeld, I didn't think of that, will try it out and let you know. I think you are correct. – shebaw May 28 '15 at 11:37
  • And what happens, if you don't use `wchar_t`? – Amartel May 28 '15 at 11:37
  • @FrankOsterfeld, Yes, got it working, thank you very much. Post your comment as an answer so that I can accept it. – shebaw May 28 '15 at 11:39

1 Answers1

1

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?

Marek R
  • 32,568
  • 6
  • 55
  • 140