[Fedora-trans-ar] RE: Arabic issue #32: The conversion of a localized 'const QString' to 'double' returns 0

Puetz Kevin A PuetzKevinA at JohnDeere.com
Mon May 9 14:18:18 UTC 2005


Right. The problem is occurring when going from const char * to QString, not when going from QString to int (which is properly locale dependent when using QLocale::toDouble). comma is in latin-1, so there's no problem. ١٢٣ is not latin-1, so won't transcode it to utf16 correctly unless it's been told to do something else.

And yes, I suspect the reason for latin1 as the standard 8bit codec is performance: latin-1 is identical to the first 256 code points of utf16, so the processing required to 'cast' 8bit const char * to utf16 QString this way is thus minimized. QString::from* methods are provided for several other common codecs (utf8 among them) to make it easy to be explicit (and there's the QT_NO_CAST_ASCII macros to force you to always be explicit), and QTextCodec for all the rest.

> -----Original Message-----
> From: Munzir Taha [mailto:munzirtaha at newhorizons.com.sa] 
> Sent: Saturday, May 07, 2005 2:59 PM
> To: qt4-preview-feedback at trolltech.com
> Cc: Puetz Kevin A; fedora-trans-ar at redhat.com
> Subject: Re: Arabic issue #32: The conversion of a localized 
> 'const QString' to 'double' returns 0
> 
> On Yaum al-Sabt 28 Rabi` al-Awal 1426 01:54, you wrote:
> > I would say that depends on whether or not you've called
> > QTextCodec::setCodecForCStrings() to tell it bare const char * and 
> > QByteArray should be interpreted as utf-8 (I believe the default is 
> > latin-1, but I'd probably be explicit if I was using anything other 
> > than ascii).
> 
> Thanks a lot Puetz for your reply but what's confusing me is if I can
>     QLocale::setDefault(QLocale::German);
>     d = QString( "1234,56" ).toDouble(&ok); // ok == true, d 
> == 1234.56 without calling QTextCodec::setCodecForCStrings() 
> or trUtf8, why not for QLocale::Arabic? Is this because the 
> German comma is within ascii range? Is this justified? Is it 
> for performance reasons that the default is latin-1 and not utf8?
> 
> > > > 	QLocale ar(QLocale::Arabic);
> > > > 	double d = ar.toDouble( "١٢٣" );
> 
> > > Now I found if I do it like this:
> > >         d = arabic.toDouble(QObject::trUtf8("١٢٣"));
> > >
> > > It works! Should I consider this bug as invalid?
> 
> 
> --
> Munzir Taha  PGP Key available
> gpg --recv-keys --keyserver www.mandrakesecure.net F0671821
> 
> Telecommunications and Electronics Engineer Mandrake Club 
> Member Maintainer of the OpenBugs project page at 
> http://www.arabic-fedora.org/munzir/OpenBugs.html
> Maintainer of Fedora Arabic Translation Project 
> https://listman.redhat.com/mailman/listinfo/fedora-trans-ar
> Master CIW Designer, ICDL, MOUS, Linux+, LPI 101 New Horizons 
> CLC, Riyadh, SA
> 
> 




More information about the Fedora-trans-ar mailing list