QString and German umlauts

I work with C ++ and QT and have a problem with German umlauts. I have a QString like "wir sind müde" and you want to change it to "wir sind m & uuml; de" in order to correctly display it in QTextBrowser.

I tried to do it like this:

s = s.replace( QChar('ü'), QString("ü")); 

But that will not work.

Also

  s = s.replace( QChar('\u00fc'), QString("ü")) 

does not work.

When I repeat all the characters of a string in a loop, "ü" are two characters.

Can someone help me?

+4
source share
2 answers

QStrings is UTF-16.

QString stores a string of 16-bit QChars, where each QChar corresponds to one Unicode 4.0 character. (Unicode characters with code values ​​above 65535 are stored using surrogate pairs, i.e., two consecutive QChars.)

So try

 //if ü is utf-16, see your fileencoding to know this s.replace("ü", "ü") //if ü if you are inputting it from an editor in latin1 mode s.replace(QString::fromLatin1("ü"), "ü"); s.replace(QString::fromUtf8("ü"), "ü"); //there are a bunch of others, just make sure to select the correct one 
+7
source

Unicode has two different representations ü :

  • Single Point 00FC (LATIN SMALL LETTER U WITH DIAERESIA)
  • Sequence 0075 (LATIN SMALL LETTER U) 0308 (COMBINED DIVERSION)

You should check both.

+1
source

All Articles