[Qt-interest] Problem in QString interpretation of single-quote closing apostrophe (’)
Julien Cugnière
julien.cugniere at gmail.com
Wed Jul 7 17:39:30 CEST 2010
2010/7/7 Sarath <sarath at softjin.com>
> int main ()
> {
> QString str = "single-quote’";
> std::cout << "str is " << str.toAscii().constData() << std::endl;
>
> return 0;
> }
> *************************************************
> The output I get when I run this program is : str is single-quoteÆ
By default, Qt assumes that your source files are encoded in Latin-1
(see QTextCodec::codecForCStrings and
QTextCodec::setCodecForCStrings). This affects the conversion of
C-Strings to QString, as well as the output of QString::toAscii().
You probably need to tell Qt the correct encoding of your source
files. If you don't know, a good guess is the system codec :
QTextCodec::setCodecForCString( QTextCodec::codecForLocale() );
If you need to output a QString to the console, I would also use
str.toLocal8Bit() instead of str.toAscii(). Although if you set the
codec for C Strings to the system codec, both will probably return the
same thing.
--
Julien Cugnière
More information about the Qt-interest-old
mailing list