[PyKDE] QString and + operator
eronlloyd at gmail.com
Fri Apr 15 01:23:13 BST 2005
On Thursday 14 April 2005 8:29 am, Phil Thompson wrote:
> > Phil Thompson <phil at riverbankcomputing.co.uk> wrote:
> >>> I'm making a requirement for a project I'm working on to work with
> > QString
> >>> instead of the built-in type as much as possible. Some will obviously
> >>> complain about this, needing to cast to str() to keep some pythonic
> > spirit
> >>> for concatenation, augmented assignment, etc. I remember seeing in this
> >>> message
> >>> (http://mats.imk.fraunhofer.de/pipermail/pykde/2002-November/003954.htm
> >>>l) that Phil mentioned supporting the '+' operator for mixed types. I
> > imagine
> >>> the problem is determining what to return. Is there still an interest
> >>> in
> >>> exposing this?
> >> I thought I had implemented it - must have slipped through the cracks.
> >> It
> >> will be in the next snapshot.
> >> Note that...
> >> q = QString("foo") + QString("bar")
> > This one is OK with me (it's a faitful binding of the existing C++
> > operator)
> > but:
> >> q = QString("foo") + "bar"
> >> ...will both work, but...
> >> s = "foo" + QString("bar")
> >> ...will not.
> > Is there a need for QString+str in the first place? If not, I'd rather
> > not have it: explicit is better than implicit :)
> > Also, having it working one way but not the other is confusing. So better
> > prohibit mixed types altogether IMO.
> I'm inclined to agree. It works because Python strings are automatically
> converted to QStrings when needed - although it is trivial to suppress
> this in this case.
Thanks for addressing this. Regarding supporting mixed types, personally I
don't see the harm in allowing it, but then I haven't used it yet so I don't
know how much helpful it would actually be. Occasionally I wish all Qt
container types were fully supported, if only to make code more consistent
with the C++ API throughout. Guess ya can't have everything...
More information about the PyQt