[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    Re: kdelibs/kdeui
From:       Oswald Buddenhagen <ossi () kde ! org>
Date:       2003-04-29 12:58:03
[Download RAW message or body]

On Tue, Apr 29, 2003 at 02:30:34AM +0200, David Faure wrote:
> On Tuesday 29 April 2003 02:25, Ravikiran Rajagopal wrote:
> > Instead of:
> > 
> > > +    QString tmp = txt + QString(" ( %1 )").arg(kapp->caption());
> > > +    setLabel( tmp );
> > 
> > use:
> > 
> > setLabel( QString("%1 (%2)").arg(txt).arg(kapp->caption()) );
> 
> Better not have a %1 in "txt" though....
>
yeah, the security thingie ... the trolls told me they would offer
something better at some point. i'm wondering what it will look like,
though.
originally i thought about using printf with positional parameters (for
i18n) like gnome does, but then it occured to me that you can't pass
objects (like QStrings) through varargs ...
so maybe something like
 QString("%1 (%2)").qarg(txt).argl(kapp->caption());
qarg() would quote any % in its argument, while argl() would do a normal
arg() and unquote the whole string afterwards. or, to make things more
consistent (but less efficient):
 QString("%1 (%2)").qarg(txt).qarg(kapp->caption()).endargs();

> I'd go for 
> setLabel( txt + " ( " + kapp->caption() + " ) " );
> 
remember that operator+ creates a copy. this creates faster and shorter
code:
 setLabel( QString(txt).append(" (").append(kapp->caption()).append(")") );
unfortunately it is less readable. but if you like it really obfuscated, 
use this one: ;)
 setLabel( ( ( txt + " (" ) += kapp->caption() ) += ")" );
(this is exactly the same machine code wise.)
not that the execution speed would matter in this case ...

greetings

-- 
Hi! I'm a .signature virus! Copy me into your ~/.signature, please!
--
Chaos, panic, and disorder - my work here is done.
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic