[PyKDE] ANNOUNCE: PyQt/PyKDE v0.11pre1

Phil Thompson phil at river-bank.demon.co.uk
Sat Mar 18 12:14:27 GMT 2000

Boudewijn Rempt wrote:

> Seems there's something to be said for medium-strength type languages ;-),
> at least in these cases... Can you tell us what _was_ the problem
> with the subclassed QListViewItems, or is it terribly complicated?

In v0.10 if a C++ object was returned that matched an existing Python
object then it was assumed it was the same object and the existing
Python object returned to the Pyton script rather than creating a new
Python object.

This broke QColorGroup (I think) because it has a QColor at the very
start of the class.  Therefore a QColorGroup has the same C++ address as
the QColor it contains.  Therefore when the QColor was being returned it
was assumed it was the existing QColorGroup and so a Python object of
the wrong type was returned to the Python script.

In v0.10.1 I changed the behaviour so that if an existing C++ address
existed *and* the matching Python object had the expected type then it
was returned.  If it had a different type, it was assumed to be a
different object at the same C++ address and a new Python object of the
expected type was created.

The problem with this approach is demonstrated with something like
QObject::parent().  In almost all cases the object returned will match
an existing Python object with a class that is derived from QObject. 
Because QObject::parent() is defined to return a pointer to a QObject
the classes don't match and so a new Python object (of type QObject) is
returned to the Python script.

v0.11 takes a more sensible middle ground.  A C++ address is assumed to
refer to an existing Python object if the Python object has the same
type as the expected type *or* if the Python object is a sub-class of
the expected type.  Therefore, if QObject::parent() returns a particular
C++ address and we find an existing Python object matching that address
and the type of that object is (say) a QLabel then we assume it is the
same object and return the QLabel Python object to the script.

So, in terms of the dirview.py example, a new Python QListViewItem was
being created and returned rather than the existing Directory.


More information about the PyQt mailing list