[PyKDE] Converions between QString and str in PyQt4

Phil Thompson phil at riverbankcomputing.co.uk
Mon Jan 23 16:20:07 GMT 2006


On Friday 20 January 2006 6:31 pm, Andreas Pakulat wrote:
> Hi,
>
> I have an issue with conversion between QString and str. The problem I
> have is as follows:
>
> create a QtCore.QVariant("true") and calling it's toBool() function
> returns false, regardless of what the string actually contains
>
> Use an explicit QtCore.QString("true") constructor and everythings fine.
>
> Now I know that in python explicit is better than implicit and thus my
> question is: Is conversion between QString and str supposed to work
> implicitly or is it expected to be done explicitly always?
>
> Currently I think both cases are mixed, if I'm not totally mistaken
> conversion from QString to str is implicitly done, but the other way
> it's not. I recall a discussion about this topic before Phil began to
> work on PyQt4, but I'm not sure about the outcome of that...

It's because the QByteArray version of the QVariant ctor appears before the 
QString version and so is being used in preference.

It will be fixed in tonight's snapshot.

Phil




More information about the PyQt mailing list