PDA

View Full Version : utf8 Problem (even in examples)



zamotf
27th December 2007, 12:05
I have my system defined to use UTF-8 (standard from the last 2 years), and I am using Mandriva 2007 and/or Mandriva 2008 with qt3 and qt4 both with the same result.

Basically, if I use the examples included in qt-examples package, and the hello world (simple), changing the "hello world" string for "ção world" or something that have ^;~;';` (needed by my language) it displays strange caracters.

Extract of the main.cpp provided with qt: (I only changed the "hello" with "ção")
The file was edit with vim using set fileencoding=utf8
Also edit with kedit to check if all was ok
....
if ( s.isEmpty() )
s = "ção, World";
Hello h( s );
....

If I check using locale, everthing appears to be ok:

LANG=pt_PT.UTF-8
LC_CTYPE=pt_PT.UTF-8
LC_NUMERIC=pt_PT.UTF-8
LC_TIME=pt_PT.UTF-8
LC_COLLATE=pt_PT.UTF-8
LC_MONETARY=pt_PT.UTF-8
LC_MESSAGES=pt_PT.UTF-8
LC_PAPER=pt_PT.UTF-8
LC_NAME=pt_PT.UTF-8
LC_ADDRESS=pt_PT.UTF-8
LC_TELEPHONE=pt_PT.UTF-8
LC_MEASUREMENT=pt_PT.UTF-8
LC_IDENTIFICATION=pt_PT.UTF-8
LC_ALL=

This is not a bug, but a miss configuration somewere. I have tryed my best, but I do not know what can I change.

I had a personal application in a old system running very well, now that I installed a new system, I am in trouble to make it work fine.

Thank you

wysota
27th December 2007, 13:17
Try:

if ( s.isEmpty() )
s = QString::fromUtf8("ção, World");
Hello h( s );

jacek
27th December 2007, 13:34
Take a look at QTextCodec::setCodecForCStrings().

zamotf
27th December 2007, 14:28
Thank you both !
Problem solved.

zamotf
28th December 2007, 07:47
For those interested in the same problem, simply changing:


s = "ção, World";

for


s = QString("ção, World");

managed the problem.
zamotf