[Qt-interest] QString::toLower() issues with two-byte chars

Øyvind Vågen Jægtnes oyvind at jaegtnes.no
Fri Mar 12 12:50:28 CET 2010


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?

---
Øyvind



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.
> Tibor
> 
> 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.
> >
> > Girish
> > _______________________________________________
> > Qt-interest mailing list
> > Qt-interest at trolltech.com
> > http://lists.trolltech.com/mailman/listinfo/qt-interest
> >

> _______________________________________________
> 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