I have a line edit that contains a file name with Unicode-characters and it displays correctly in the GUI, but when I print it with qDebug()
, it shows the Unicode symbols as question marks.
For example, for "C:/Test/абв"
this code will show only "C:/Test/???"
.
This line:
qDebug() << ui->lineEditFileName->text();
Would show:
This problem happens only on Windows (both XP and 7), on Linux it works fine. The version of Qt is 4.8.0.
Linux uses Unicode for it's terminal, Windows - does not. You can find out, which code page is used by typing
chcp
incmd
. What you need is to convert your string, using this code page before outputting it:Or set it for all c-strings:
The second piece of code will make "CP866" the default codec for all strings in your program.
Also check this "Region and Language" -> "non-Unicode Programs" setting in Control Panel. It`s helped me to fix wrong symbols in debug console.
It seems that the Unicode text is 'lost in translation', because Qt Creator uses
QString::fromLocal8Bit()
when reading the debug output from the process.I found the answer from this thread: