[PyKDE] "None" conversion to QString?

Phil Thompson phil at riverbankcomputing.co.uk
Sat Apr 9 16:24:34 BST 2005


On Saturday 09 April 2005 11:08 am, Giovanni Bajo wrote:
> Hello,
>
> 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.

Phil




More information about the PyQt mailing list