[Qt-interest] Source files encoding

Andrew Wong andrew.w at sohovfx.com
Wed Oct 13 23:26:54 CEST 2010


>From QString's docs:
	QString converts the const char * data into Unicode using the fromAscii() function. By default, fromAscii() treats character above 128 as Latin-1 characters, but this can be changed by calling QTextCodec::setCodecForCStrings().

I haven't tried it, but I think this might work:
	TextCodec::setCodecForCStrings( QTextCodec::codecForName("UTF-8") )

This will affect *all* QString that'll be created though... so watch out for any undesirable effect.



On Wednesday 13 October 2010 04:45:57 pm Marcelo Magno T. Sales wrote:
> Hello,
> 
> Editing/compiling a project in QT Creator 1.3.1 on Linux (Kubuntu 
> 10.04), all strings that contains accented characters are displayed 
> wrong when the generated executable is run.
> This can be solved by saving the source files as ISO8859-1 or by adding 
> QString::fromUtf8() around the strings in the source. However, I'd 
> rather use my system's default encoding (UTF-8) than saving every file 
> as ISO8859-1 and having to select this encoding manually every time I 
> open the file in QT Creator editor. Adding QString::fromUtf8() around 
> every single string in the source code is not a very appealing solution 
> either.
> Although g++ documentation states it should default to utf-8 for its 
> input files, I've tried to add:
> QMAKE_CXXFLAGS += -finput-charset=utf-8
> to the project file, but the problem persists.
> 
> Is there a way to compile from UTF-8 encoded sources in Linux and get 
> the right strings displayed in the executable?
> 
> Thanks,
> 
> Marcelo
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
> 




More information about the Qt-interest-old mailing list