PDA

View Full Version : QString::toLatin1() with umlauts



dape
16th October 2010, 15:09
Hi everyone,

i'm trying to convert an url to latin1 percentage encoding. QUrl::toPercentageEncoding only encodes to UTF-8.
I need this because I want to send a request to a server. This server expects latin1 percentage encoding for example for usernames with umlauts (öäüß...).

Does anyone know how i can do this easily with QT?

I tried it to convert the Strings to latin1 and use the hexcode, but there seems to be a problem.
Why does "qDebug() << QString( "ä" ).toLatin1().toHex();" output "c3a4" (UTF-8) ???
I assumed the latin1 conversion "e4".

Thanks in advance.

Regards,
Daniel

Lykurg
16th October 2010, 17:36
Assuming your source file is encoded with utf8, so you have to use:
qDebug() << QString::fromUtf8("ä").toLatin1().toHex();.