Qt unicode and umlauts

Since we converted all source and header files to unicode, we have problems with German umlauts. Everything is fine, but QLabels and other gui components show umlaut distortions.

The ISO-8859-1 source is working fine, but causes problems when switching between OSX and Windows.

Is there anything I need to install in the project file?

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

Example

+6
source share
2 answers

Try to call

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

immediately after creating the QApplication object. QTextCodec::setCodecForTr is only required when using tr() .

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

+10
source

I had a similar problem and decided to use only 7 bit ASCII characters in my source files and install QTranslator, which creates umlauts.

Since the application needs to be translated into other languages, this seems like a good way to avoid coding problems.

0
source

Source: https://habr.com/ru/post/891633/


All Articles