Results 1 to 5 of 5

Thread: Help needed to convert unicode characters

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2009
    Posts
    22
    Thanks
    2
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Help needed to convert unicode characters

    Thanks, I thought I'd better give some context in the way the JSON is used. I have tried converting raw back to a const char* and using QString::fromUtf8 but that doesn't work either.

    As you can see the QString does contain \u00e9, I guess what is going on here would be like if "\n" was treat as two separate bytes and printed as '\' 'n'.

    Qt Code:
    1. struct JSONProcessor : public RPCRequest::Processor
    2. {
    3. virtual QVariant process( const QString& raw )
    4. {
    5. // This is what raw looks like
    6. // "{\"data\":[{\"id\":\"535666\",\"readable\":true,\"title\":\"B\u00e9linda\"}]}";
    7.  
    8. //this doesn't work
    9. //qDebug() << QString::fromUtf8(raw);
    10.  
    11. return someProcessing( raw );
    12. }
    13. };
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Help needed to convert unicode characters

    OK. Nothing in the standard Qt bag-o-tricks will do this for you. You need to disassemble and un-escape the escaped elements, e.g. \" or \u00e9, yourself using QRegExp, QString etc. (see http://www.ietf.org/rfc/rfc4627.txt) or use something like QJson (LGPL) to do it for you. I would go the second route unless licences prohibit you.
    Last edited by ChrisW67; 5th July 2012 at 06:18.

  3. The following user says thank you to ChrisW67 for this useful post:

    hybrid_snyper (24th August 2012)

  4. #3
    Join Date
    Oct 2009
    Posts
    22
    Thanks
    2
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Help needed to convert unicode characters

    Just thought I would close this thread off and point to the solution that helped me. Turned out the API I was talking to was returning a 'unicode' string representation of special characters and not unicode.

    Anyways this helped http://www.qtcentre.org/threads/3731...icode-Problems

Similar Threads

  1. Replies: 0
    Last Post: 7th June 2012, 21:58
  2. Replies: 6
    Last Post: 30th March 2012, 08:01
  3. QString to unicode characters
    By jsmax in forum Newbie
    Replies: 1
    Last Post: 19th September 2011, 10:41
  4. Unicode/ASCII characters in QTextStream
    By yren in forum Qt Programming
    Replies: 3
    Last Post: 23rd November 2009, 18:25
  5. Insertion of unicode characters into database oracle through pro c
    By hemananda choudhuri in forum Qt Programming
    Replies: 1
    Last Post: 8th January 2007, 10:42

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
  •  
Qt is a trademark of The Qt Company.