drawText cannot draw latin word correctly
I am using QT 4.7.3 under embedded linux platform.
I got a problem.
I use command (mount -o iocharset=iso8859-1,utf8) to mount usb disk.
and get the file name list in QT application.
And there is a file that name is FüllungRaupeStep
The file name could be show correctly in linux console.
But , it shows FÃ¼llungRaupeStep in my GUI when I invoke QPainter.drawText to show it.
I tried to show it by qDebug
the result as following.
QString text = tr("FüllungRaupeStep");
qDebug() << text; //output is FüllungRaupeStep (O)
qDebug() << text.toUtf8(); //output is FÃ¼llungRaupeStep(X)
qDebug() << text.toLatin1(); //output is FüllungRaupeStep(O)
painter.drawText(rect, align_flag, text.toLatin1()); //output is FÃ¼llungRaupeStep(X)
painter.drawText(rect, align_flag, text.); //output is FÃ¼llungRaupeStep(X)
painter.drawText(rect, align_flag, text.toUtf8()); //output is FÃ¼llungRaupeStep(X)
Does any one have idea?
@yifong Could be the font. You could try another font using http://doc.qt.io/archives/qt-4.8/qpainter.html#setFont
Thanks for reply.
I think it is not font problem , because ü could be show if I use following method.
painter.drawText(rect, align_flag, QString(QChar(0x00FC)); // ü is showed correctly.
So, the applied font is support to show ü. :)
the tr() methods expects the string to be latin-1 encoded. By passing "ü" the latin-1 representation is "Ã¼" (of "ü" from UTF-8)
So you are advised to pass only ASCII characters to tr() and translate them later (what i assume is your intention in the first place since you use tr()).
If you don't want the string be translated simply use
Thanks for your answer
You are right .
Finally I solve this problem by following method.
painter.drawText(rect, align_flag, QString::fromUtf8(qPrintable(text)));
"ü" could be show correctly. :)