Results 1 to 2 of 2

Thread: Converting accented characters to std::string returns mangled text

  1. #1
    Join Date
    Oct 2016
    Posts
    5
    Qt products
    Qt5
    Platforms
    Windows

    Question Converting accented characters to std::string returns mangled text

    If my QString's value is

    Qt Code:
    1. WeÅ .txt
    To copy to clipboard, switch view to plain text mode 

    the function QString::toStdString() will return

    Qt Code:
    1. WeÃ… .txt
    To copy to clipboard, switch view to plain text mode 

    whereas the function QString::toStdU16String will return the actual string

    Qt Code:
    1. WeÅ .txt.
    To copy to clipboard, switch view to plain text mode 

    Why is that ? Å is a UTF-8 character as can be seen here : http://www.fileformat.info/info/charset/UTF-8/list.htm.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,194
    Thanks
    237
    Thanked 668 Times in 658 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Converting accented characters to std::string returns mangled text

    std:: string is a template specialization of std:: basic_string<T>, with T being "char". If you want conversion of non-ASCII characters, you need to use std:: wstring (which is the basic_string specialization that uses wchar_t). The QString conversion is QString::toStdWString().
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. XKeySymToKeyCode returns 0 for unicode and special characters
    By Deepika in forum General Programming
    Replies: 0
    Last Post: 16th July 2015, 14:21
  2. Problem with accented characters
    By gt.beta2 in forum Qt Programming
    Replies: 2
    Last Post: 14th April 2009, 22:20
  3. [perl] converting a string
    By mickey in forum General Programming
    Replies: 5
    Last Post: 26th March 2009, 14:33
  4. converting of string to enum
    By jjbabu in forum Qt Programming
    Replies: 2
    Last Post: 24th October 2008, 17:31
  5. Converting number to string.
    By safknw in forum Newbie
    Replies: 2
    Last Post: 18th September 2006, 13:12

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.