Results 1 to 1 of 1

Thread: Convert euro sign from QString to UTF-8

  1. #1
    Join Date
    Mar 2013
    Posts
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Convert euro sign from QString to UTF-8

    Hi all,

    from a cross platform project i had to convert the euro symbol to store it to an UTF-8 coded database. To make the problem more complex; database requests are made via LUA.

    The euro symbol is entered by a QTextEdit and i do some function calls like the following lines:

    Qt Code:
    1. ...
    2. // Function called from LUA to convert Data to be stored
    3. static
    4. string StrToUTF8 (
    5. const char* Source
    6. )
    7. {
    8. string result;
    9. if ( Source && Source [ 0 ] )
    10. {
    11. QString converter ( QString::fromLocal8Bit ( Source ) );
    12. result = converter.toUtf8 ().constData ();
    13. }
    14. return result;
    15. }
    16.  
    17. ...
    18. QString text (textedit -> text ());
    19. qDebug () << "FromEdit:" << text << "," << text.toLocal8Bit ().constData ();
    20. // Call a lua function
    21. WriteToDatabase (text.toLocal8Bit ().constData ());
    22. ...
    To copy to clipboard, switch view to plain text mode 
    So the UTF-8 value for euro symbol should be E2 82 AC. But i alway got E2 80.

    Any suggestions what i am doing wrong?

    Platform is Windows 7, Windows XP and embedded Linux.

    BTW: reading UTF-8 by calling QString::fromUtf8 () works fine.

    Kind regards

    Spiderghost


    Added after 17 minutes:


    Sometimes it helps to explain some part of code ... after writing this part and comparing it to the original code, i saw at once that the part "QString::fromLocal8Bit ( Source )" was missing ...

    Thank you for listing. The problem was sitting in front of my screen ...

    Kind regards

    Spiderghost
    Last edited by Spiderghost; 22nd March 2013 at 15:27.

Similar Threads

  1. QString::fromUtf8 problems converting micro sign
    By smacchia in forum Qt Programming
    Replies: 3
    Last Post: 15th February 2011, 23:07
  2. Euro sign
    By dragon in forum Qt Programming
    Replies: 3
    Last Post: 8th September 2008, 20:58
  3. convert QString to int
    By mattia in forum Newbie
    Replies: 2
    Last Post: 4th January 2008, 10:10
  4. Problem Euro Sign with QLineEdit
    By Kubil in forum Qt Programming
    Replies: 1
    Last Post: 24th August 2007, 05:56
  5. How to convert Int to QString in QT4?
    By drake1983 in forum Newbie
    Replies: 2
    Last Post: 11th March 2007, 07:58

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.