From kde-commits Tue Apr 29 12:58:03 2003 From: Oswald Buddenhagen Date: Tue, 29 Apr 2003 12:58:03 +0000 To: kde-commits Subject: Re: kdelibs/kdeui X-MARC-Message: https://marc.info/?l=kde-commits&m=105162108731635 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.