inefficient QString coding practice

Lars Knoll lars at trolltech.com
Sat Mar 13 18:35:21 GMT 2004


On Saturday 13 March 2004 15:02, Harri Porten wrote:
> On Sat, 13 Mar 2004, Adriaan de Groot wrote:
> > >   if (extension == QString::fromLatin1(".wav"))
> >
> > ...
> >
> > > Conclusion: let QT do the job - and change code like the example above
> > > to keep KDE small and fast.
> >
> > That's an interesting point, _if_ there is a way to find out when there
> > is such a method available (including in old code). See, going through
> > and removing all the ::fromLatin1()s and seeing if it compiles is _not_ 
> > a pleasant job (and don't forget the effect QT_NO_CAST_ASCII and
> > _NO_ASCII_CAST have).
>
> Time for a compareWithLatin1() member or global function! :)

We actually know about this problem and already have a solution for this in Qt 
4. It's called QLatin1String and is a simple wrapper around a const char *.

So you can then write

if(str == QLatin1String("foo")) { ... }

and the code will
a) compile with NO_CAST_ASCII and 
b) avoid the temporary QString.

But that's Qt 4.....

Cheers,
Lars





More information about the kde-core-devel mailing list