[PyKDE] "None" conversion to QString?

Giovanni Bajo rasky at develer.com
Sun Apr 10 18:02:30 BST 2005

Phil Thompson <phil at riverbankcomputing.co.uk> wrote:

>> is there a point on allowing None to be converted to QString, that
>> is to match QString in argument list of functions?
>>>>> from qt import *
>>>>> a = QApplication([])
>>>>> QPushButton("foo", None)
>> <qt.QPushButton object at 0x00813600>
>>>>> QPushButton(None, None)
>> <qt.QPushButton object at 0x008135D0>
>> This makes it impossible for instance to disambiguate between the
>> constructors of QListViewItem, for instance:
>> QListViewItem(QListViewItem* parent, QString label1, QString label2
>> = "", QString label3 = "")
>> QListViewItem(QListViewItem* parent, QListViewItem* after, QString
>> label1, QString label2 = "", QString label3 = "")
>> If you call this as:
>> QListView(None, None, "foo")
>> PyQt will effectively call the first constructor rather than the
>> second. I believe I could use sip.cast to disambiguate but I would
>> like to know the rationale behind the choice of allowing None as
>> null string. 
> Hmm - a good question. Apart from QByteArray, QCString and QString,
> PyQt consistently maps NULL to None and vice versa. I suspect its
> from the early days of PyQt when the signature checking wasn't as
> sophisticated and, in particular, didn't check when it knew a pointer
> was going to be dereferenced. 
> The current behaviour is wrong and I'll change it. There is a danger
> that the change might break some code.

Yes, but as with the typed enum change, it's for a good cause. Thanks.

Giovanni Bajo

More information about the PyQt mailing list