Qt5 and umlaut
-
Hi!
I just switched from Qt4 to Qt5 and have the following problem:
Umlauts are not working correctly. For instance, the following was working fine in Qt4ui_.label->setText("üäö")
In Qt5 however, I have to write
ui_.label->setText(QStringLiteral("üäö"))
to make it work. This is annoying and I am hoping for a solution here.
What's more of a problem is thisui_.label->setText(tr("üäö"))
I dont know how to migrate such a call to Qt5, since I obviously can not use QStringLiteral within the tr macro and also trUtf8 is not working correctly.
I am using Visual Studio 2010, the encodings of my files are NOT Utf8 and I am actually hoping to keep it that way.
Can you help me pls?
Cheers
-
I've answered a similar question before: https://qt-project.org/forums/viewthread/7865/
Incidentally, you could use QString::fromLatin1("üäö"), QString::fromLocal8Bit("üäö"), QString::fromUtf16("üäö"), depending on your file encoding.
However I maintain that your source code should be in programmer English and using only ASCII characters. Every other language (including actual English) should be done using Qt's translation system.
-
I would say that it was never a reliable way of doing things to begin with. But to actually answer your question, there is no way to use this exactly as before save by using Qt4. QString assumes const char * to be pointing to an utf-8 encoded string since Qt5. If you don't have that or don't want that, use QLatin1String, or QString::fromLatin1(). However, the file encoding issues may still hit you when switching platforms.
-
I changed the encoding of my files to UTF-8 now, but translating still doesnt work:
qApp->translate("testcontext", "äöü"))
The problem with my library is, that must of the text written there is even before it was migrated to qt4 and most of the text is german. Do I really have to change each line of text to english and redo the translation completely? (this time translate english -> german instead of german -> english)
-
Did you fully read http://qt-project.org/wiki/Strings_and_encodings_in_Qt ?
-
I read a lot but I didn't understand too... :-)
Now I have found two ways that seem to work:1.)
What Frankz said works ("...source code should be in programmer English and using only ASCII characters.")2.)
Save your sources as Utf-8 without byte order mark. That's what the Qt creator usually seems to do and tr("Mötörhead") works fine.
If you use Visual Studio you will have to select "Unicode (UTF-8 without signature) - Codepage 65001" for every file you save.
There seems to be no way to configure this in the Studio's standard settings for all saved files.