PDA

View Full Version : QString toLatin1() / toAscii() error with additional characters



android_
2nd March 2010, 17:36
Hey,
i have a QString which is converted to a Latin1 char via toLatin1(). As i'm from europe the text will contain special characters like ä,ö,ü.
The problem is that for example the character "ä" is converted to -28 (seen with visual studio debugger). I don't even know that conversion to a negative value was possible?! Same for toAscii(), the value is -28 in the debugger, conversion to int is also -28, using atoi() returns 0 and converted to an unsigned int is the number 4294967268.
what am i doing wrong?

The text comes from a QTextEdit and is converted via toPlainText()

Lykurg
2nd March 2010, 21:46
Well, you wonder why umlauts could not be encoded to ascii? It's because they are not covered by ascii. Well, serious, what do you want to achieve? Why is it necessary to use toAscii or toLatin1? Qt uses utf8 as default encoding and you can work fine with that. Also toPlainEdit returns a QString which is correctly encoded in Utf8 with your umlauts.

android_
3rd March 2010, 11:08
I thought they were covered in Latin1. I have to modify an existing part of code and it seems to be crucial for one part to use characters. It seems that i have to figure out another way, thanks.