PDA

View Full Version : Retrieve string codec



Raccoon29
5th December 2008, 10:57
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)


QTextCodec *codec=QTextCodec::codecForName("UTF-8");
lineEdit->setText(codec->toUnicode("€ "));

but results in a square.

Thank you in advance

jpn
28th December 2008, 20:52
Perhaps your source file is not saved in UTF-8. ICU (http://icu-project.org/) is able to detect encoding but it's probably overkill for what you're trying to do. What are you actually trying to do?

Raccoon29
21st January 2009, 16:17
Perhaps your source file is not saved in UTF-8. ICU (http://icu-project.org/) 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

LineEdit->setText("€");
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:

QString EURO=QApplication::translate("frmmain", "\342\202\254", 0, QApplication::UnicodeUTF8);
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. :)

Palmik
26th January 2009, 21:21
Hi, you can also try
LineEdit->setText(trUtf8("€")); which works perfectly fine for me