PDA

View Full Version : Displaying 'Ñ' or 'Ù' in a label



kristen
10th August 2007, 17:23
Hello there,

I'm new to Qt as well as to Linux, running Qt on a french-speaking linux system but trying to use my home language (Breton) in my progs. Unfortunately, while Designer is quite happy with QStrings containing characters like 'ñ', 'Ñ' or 'Ù', the prog once compiled displayed senseless things instead of them.

I tried to use the QString members .latin1() and .utf8(), with no success though. I thought maybe the Hispanic community could help ! ;)

Thanks for reading

Kristen

marcel
10th August 2007, 17:34
You have to install a codec for unicode.
It is used in const char* to QString conversions.


QTextCodec::setCodecForCStrings(QTextCodec::codecF orName("utf-8"));


You must use this before you set any characters in your labels. Preferably, add it in main.cpp, after you instantiate the QApplication object.

Then in code, you can use either the character itself, if your IDE supports it, or use the unciode code for it when you build the QString:


QString str="\u03c3\u05c3";


Something like this.

Regards

kristen
10th August 2007, 18:27
Thanks Marcel for showing me the way !

It does work now. 2 steps :

1 - #include <qtextcodec.h> + in the constructor : QTextCodec::setCodecForCStrings(QTextCodec::codecF orName("utf8"));

2 - for displaying in a widget, change myWidget->setText(mystring) into myWidget->setText(mystring.latin1()) !

At least, that's the way I get all the characters needed both in Designer and at run time.

Thanks again
Kristen