Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt unicode and umlauts

Since we've converted all our source and header files to unicode, we're facing problems with german umlauts. Everything is fine in the source but QLabels and other gui components are showing umlauts garbled.

ISO-8859-1 source works fine but causes problems when switching between OSX and Windows.

Is there anything I have to set in the project file?

Environment: Qt 4.7 with Qt Creator 2.3.0 using MinGW on Windows XP SP3

Example

like image 647
atamanroman Avatar asked Jun 29 '11 12:06

atamanroman


1 Answers

Try to call

QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));

just after creating the QApplication object. QTextCodec::setCodecForTr is only needed if your using tr().

EDIT: This works only for Qt older than version 5. Newer Qt versions expect the source files to be converted to UTF-8.

like image 122
Raiv Avatar answered Sep 20 '22 14:09

Raiv