QDebug output with UNICODE characters to Windows Console/QtCreator. Mission impossible?
Seems that outputing UNICODE characters to Windows console and QtCreators' "Application output" is almoust mission impossible :).
I need to use some greek alphabet letters in my program so I need to work with UNICODE characters. With GUI there is no problems, but as soon as I started using QDebug I found that debug output is messy. Do I something wrong? Please see "Screenshots":https://skydrive.live.com/?cid=5aaffdcea54ab9b5&id=5AAFFDCEA54AB9B5!565&sff=1#cid=5AAFFDCEA54AB9B5&id=5AAFFDCEA54AB9B5!565
- I set codec to UTF8 - QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
- As internet sources tell "Output unicode strings in Windows console app":http://stackoverflow.com/questions/2492077/output-unicode-strings-in-windows-console-app , it is impossible to output UNICODE characters to Windows console without additional calls to Win32.
- I am not sure about QtCreators' "Application output" window. Seems that it does not support UNICODE at all.
- I think this is buggy behaviour. What is your opinion?
I am using: Windows 7 Pro 32bit, Qt 4.8.2 (VC2010), QtCreator 2.5.2
I don't know what qDebug uses to put strings onto the console on windows (I assume QString::toLocal8Bit). I know that Qt Creator uses QString::fromLocal8Bit(...) to read the text from the process. That works great everywhere... but unfortunately there is one OS out there that still insists on using codepages that completely break any attempt to display more than one kind of script at a type.
QDebug() uses QString::fromLocal8Bit(...) for converting internal QString buffer to char array and passing it to installed message handler (qInstallMsgHandler(...)).
I did some more testing and resume is:
Linux - qDebug output with unicode works: in QtCreators' "Application output"; in terminal when you run program as a separate process; Does not work in qtcreator_process_stub which is used for displaying console app output when application is started from within QtCreator.
Mac OSX - same as with linux ...
Windows - qDebug output with unicode does not work at all. You can make it work on a Windows command shell if you call Win32 function "SetConsoleOutputCP(CP_UTF8);". I have no idea how to achieve this in QtCreators' "Application output".
I am not sure how to treat all this. On one hand debug output is used mostly by app developers. It is not a big problem if debug output is slightly messy. But in my opinion fix is needed for console applications in Windows. And in general maybe it would be good to mention all this in Qt docs so that other people can read and understand what is happening instead of digging in.
qtcreator_process_stub eating unicode is definitely worth a "bug report":http://bugreports.qt-project.org/ ! It should be fully transparent wrt. output received by the application. IIRC it was introduced so we could make sure that the application we start from creator is really getting killed in a reliably way on all platforms.
Ok. I'll make a bug report for qtcreator_process_stub. And I'll also make a bug report for console app on windows. I think Qt should call “SetConsoleOutputCP(CP_UTF8);” automatically for console applications on windows platform ...
everybody please vote for this bug, thanks.