[PyKDE] QString in PyQt4 - Request for Comments

Baz Walter bazwal at ftml.net
Tue Oct 18 20:05:14 BST 2005


On Tuesday 18 Oct 2005 18:24, Phil Thompson wrote:
> I'm wondering whether QString should be dropped in PyQt4 in order to make
> it more Pythonic.
>
> At the moment Python strings and unicode strings are automatically
> converted to QStrings when passed as arguments - so there would be no
> change there. If a QString was returned by a method or an operator then a
> unicode string would be returned instead.
>
> Obviously you would lose all of QString's methods and would have to rely on
> what Python gives you for manipulating strings.
>
> One of the limitations of QString has been that you couldn't do...
>
> q = "Py" + QString("Qt")
>
> ...but with current snapshots you can - so this is an argument for keeping
> QString as it has become easier to use.
>
> BTW, the following is a consequence of the additional support...
>
> s = "Py"
> # s is of type str
> s += QString("Qt")
> # s is now of type QString
>
> Comments, opinions welcome.
>

My immediate thoughts on this are that it is a great idea. Never having to 
worry again about making explicit conversions between pystrings and qstrings 
just fills me with joy. I have never found a single reason to prefer qt's 
string handling to python's - quite the opposite, in fact. Working with 
qstrings was probably one of the few things I found difficult when starting 
to use pyqt. I soon learned the best way to handle them, though: immediate 
conversion to a python unicode object :-)

So, a definite +1 from me on getting rid of QStrings.

python-comes-before-qt-in-pyqt-ly yours

-- 
Baz Walter




More information about the PyQt mailing list