views:

715

answers:

2

I have a Win32 console app that is showing this behavior.

1) Using VC 2005 cl to compile and link, the application works fine. What I mean by working fine is that characters above 128 display correctly according to Code Page 437.

2) When I use QT qmake to construct a project (QT += console) and SOURCES = main.c, the build goes fine and my main.exe is created. But the characters above 128, using WriteConsoleOuput function display differently (some weird characters). I have the felling that this has to do with the Code Page not being set up correctly. I did not call any QT functions, neither have I created QApplication, or QCoreApplication object. When I created QApplication Object or QCoreApplication Object, the results where the same (Not displaying the correct characters).

Is there anyway to display the characters above 128 correctly using Win32 console and QT ?

Thank you.

A: 

I certainly wouldn't recommend using WriteConsoleOuput if that's a Windows specific API. Qt provides an easy way to write out strings using QTextStream:

// setup
QFile f;
f.open(stdout, QIODevice::WriteOnly);
QTextStream qout(&f);

// usage
qout << tr("translate this text");

I would recommend you use UTF-8 for everything, if possible. Then you don't have to worry about the different encodings, etc. If you are required to output in your local encoding for some reason, then consider QString::fromLocal8bit().

Kaleb Pederson
How can QTextStream be used to add colour to the text to be output, and position the cursor ?
A: 

Thank you,

I solved the problem by using WriteConsoleA functions.

just for the next time, you also can write a comment to an existing answer. But no offense :)
Berschi