Results 1 to 3 of 3

Thread: QString toLatin1() / toAscii() error with additional characters

  1. #1
    Join Date
    Jun 2009
    Posts
    13
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Post QString toLatin1() / toAscii() error with additional characters

    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()

  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() / toAscii() error with additional characters

    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.

  3. #3
    Join Date
    Jun 2009
    Posts
    13
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QString toLatin1() / toAscii() error with additional characters

    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.

Similar Threads

  1. Quick QString question: Using " characters in QStrings
    By JPNaude in forum Qt Programming
    Replies: 2
    Last Post: 6th March 2009, 07:30
  2. Error regarding QString
    By Namrata in forum Newbie
    Replies: 3
    Last Post: 22nd October 2007, 09:00
  3. Replies: 11
    Last Post: 11th October 2007, 16:34
  4. Replies: 2
    Last Post: 6th October 2006, 08:54
  5. QString ~ QByte error
    By mhoover in forum Qt Programming
    Replies: 2
    Last Post: 7th March 2006, 20:01

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.