Results 1 to 4 of 4

Thread: Retrieve string codec

  1. #1
    Join Date
    Sep 2007
    Location
    Sant'Elpidio a Mare, Italy
    Posts
    194
    Thanks
    54
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Retrieve string codec

    Hi all,

    simple question: how is it possible to retrieve the codec that a string is using?

    I need it to encode the € char to Unicode for a QLineEdit (it appears as a square).
    If there is a simpler way, I'm earing

    I'm using this code (from docs)
    Qt Code:
    1. QTextCodec *codec=QTextCodec::codecForName("UTF-8");
    2. lineEdit->setText(codec->toUnicode("€ "));
    To copy to clipboard, switch view to plain text mode 
    but results in a square.

    Thank you in advance
    --
    raccoon29

    "La mia vita finirà quando non vedrò più la gente ridere...non necessariamente alle mie battute "

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Retrieve string codec

    Perhaps your source file is not saved in UTF-8. ICU is able to detect encoding but it's probably overkill for what you're trying to do. What are you actually trying to do?
    J-P Nurmi

  3. #3
    Join Date
    Sep 2007
    Location
    Sant'Elpidio a Mare, Italy
    Posts
    194
    Thanks
    54
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Retrieve string codec

    Quote Originally Posted by jpn View Post
    Perhaps your source file is not saved in UTF-8. ICU is able to detect encoding but it's probably overkill for what you're trying to do. What are you actually trying to do?
    Sorry, I'm late, I always forgot to reply...
    anyway I found a "solution" for this, but I don't know if it is "so fine".

    I was trying to put an Euro symbol ( € ) in a QLineEdit, but if inserted by
    Qt Code:
    1. LineEdit->setText("€");
    To copy to clipboard, switch view to plain text mode 
    results in a square (unknown char). But since QtDesigner is able to put an Euro char in the QLineEdit, so I "asked" him how it was doing. Then watching the resulting ui file, I saw it wrote something like the following:
    Qt Code:
    1. QString EURO=QApplication::translate("frmmain", "\342\202\254", 0, QApplication::UnicodeUTF8);
    To copy to clipboard, switch view to plain text mode 
    Eventually I used this code and it works, but actually I don't know exactly what it means, so if someone could explain it, it would be great. The end.
    --
    raccoon29

    "La mia vita finirà quando non vedrò più la gente ridere...non necessariamente alle mie battute "

  4. #4
    Join Date
    Jan 2009
    Location
    Czech Republic
    Posts
    26
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Retrieve string codec

    Hi, you can also try
    Qt Code:
    1. LineEdit->setText(trUtf8("€"));
    To copy to clipboard, switch view to plain text mode 
    which works perfectly fine for me

Similar Threads

  1. Reading from sockets in a multithreaded program
    By KoosKoets in forum Qt Programming
    Replies: 9
    Last Post: 4th April 2007, 20:43
  2. saving a c string of variable length in a shared memory?
    By nass in forum General Programming
    Replies: 4
    Last Post: 3rd January 2007, 14:40

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.