Output funky UTF-8 to console
-
I have a console program that uses various QT classes. It needs to be translatable into Japanese.
I am pretty sure my terminal is showing such glyphs correctly, as I have a directory named 我能吞下玻璃而 that quite happily appears in my Gnome terminal.
I thought I'd start by making one of the QStrings inside the console contain some of these characters, and just see if I can get them all the way out to the console. I cannot :(
The QString is question is created like this:
@const QString Message_Location(QObject::tr(" 形声文字 of : "));@It is then passed to a QTextStream& object, m_output;
@ m_output << Message_Location << endl;@m_output seems to be a reference to a QTextStream object created like this in an initialiser list:
@m_stdOutput(stdout, QIODevice::WriteOnly)@The output I actually get in the console is:
@形声æå of@
although on my console some of that is those little rectangles with numbers in that one gets when something's gone wrong with the character handling.Right before this line executes:
@ m_output << Message_Location << endl;@
I can use the debugger and see that Mesasge_Location is a QString containing the value @形声æ\226\207å\227 of@I really don't know where to look first for something like this. Can anyone help?
-
Hi,
You need 3 things:
- Your .cpp file needs to be saved as a UTF-8-encoded file
- You must write your code using "UTF-8 string literals":http://en.wikipedia.org/wiki/C++11#New_string_literals
- You must enable C++11 support in your compiler