Results 1 to 2 of 2

Thread: QString::toLatin1() with umlauts

  1. #1
    Join Date
    Oct 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question QString::toLatin1() with umlauts

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QString::toLatin1() with umlauts

    Assuming your source file is encoded with utf8, so you have to use:
    Qt Code:
    1. qDebug() << QString::fromUtf8("ä").toLatin1().toHex();
    To copy to clipboard, switch view to plain text mode 
    .

Similar Threads

  1. With QString create a QString&
    By avis_phoenix in forum Newbie
    Replies: 1
    Last Post: 21st April 2010, 22:05
  2. Replies: 2
    Last Post: 3rd March 2010, 10:08
  3. Replies: 4
    Last Post: 1st February 2010, 14:21
  4. Replies: 4
    Last Post: 31st January 2008, 20:44
  5. how to copy part of QString to anothe QString
    By nass in forum Qt Programming
    Replies: 1
    Last Post: 26th March 2007, 19:05

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.