[Qt-interest] QString::toLower() issues with two-byte chars
Nikos Chantziaras
realnc at arcor.de
Fri Mar 12 13:03:44 CET 2010
The static QTextCodec::codecForLocale() should probably help here. So
doing a:
QTextCodec::setCodecForCStrings(QTextCodec::codecForLocale());
at the start of your application should theoretically always result in
"the right thing" regardless of the user's system codec.
On 03/12/2010 01:50 PM, Øyvind Vågen Jægtnes wrote:
> Thank you, they both worked like a charm!
> I forget that not everyone are sitting at a UTF-8 enabled terminal ;)
>
> But this brings up another issue that might come down the road. What
> happens if someone runs this program in a latin1 terminal and inputs
> the same types of chars? Is there a way to detect the encoding of the
> terminal one is running at?
>
> On Fri, Mar 12, 2010 at 08:14:51AM +0100, Tibor Kiss wrote:
>> Or you can try to do this in your main() before anything else:
>>
>> QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
>> QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
>>
>> Hope this helps.
>>
>> 2010/3/12 Girish Ramakrishnan<girish at forwardbias.in>
>>
>>> Øyvind Vågen Jægtnes wrote:
>>>> Hi,
>>>>
>>>> I have some problems using QString::toLower() on strings containing
>>>> norwegian chars.
>>>>
>>>> A simple test program:
>>>>
>>>> #include<QtDebug>
>>>>
>>>>
>>>> int main(int argc, char **argv)
>>>> {
>>>> qDebug()<< QString("æøå").toLower();
>>>> return 0;
>>>> }
>>>>
>>>
>>> The QString(char *) constructor assumes that the c-style string is
>>> ASCII. The above code is equivalent to
>>> QString::fromAscii("æøå").toLower() which is not what you want.
>>>
>>> So, do QString::fromUtf8("æøå") and then you will get expected results.
More information about the Qt-interest-old
mailing list