[PyKDE] Destructor trouble (how to get rid of child widgets ?)

Thomas Malik Thomas.Malik at t-online.de
Sat May 20 16:24:07 BST 2000


Excuse my somewhat lengthy email.

Somehow, i found it being quite difficult to destroy & recreate widgets in
dialogs. In my program, i am using a QTabDialog with two pages, one where
you
can select the type of some object in a QListBox, and one page in which you
can
edit properties of the object (by means of different kinds of QLineEdits,
QComboBoxes, checkboxes & others, with a QLabel on their left side,
everything
arranged within a QFrame by a QGridLayout). The properties are specific to
the
object type, so what happens is, if you select a different object type, the
second property page will change to a different set of object properties.

The problem is, even if i ensure to have no more reference to the old
widgets (i
'del' them all, & my classes don't pass any references outside, i even
checked
with sys.getrefcount), everything stays where it was. So, if i selected
different object types in my QListBox on the first page, the lineedits &
others
in the other page accumulate, rendering it unusable. I tried to establish
destructors, but i found no way of getting rid of or reinitialising the
QGridLayout. So, with removeChild & destroy in destructors for the 'property
objects', it works some how but gives me X Error after a while (propably
accessing an already destroyed window.

I also tried to completely remove the 'properties' page from the QTabDialog,
but
didn't find any way to do so. Just deleting the QFrame python object didn't
help. At that point, a related problem shows up: QObject.children() only
partially returns the correct class of child objects. Child Objects created
by
the qt library seem to always show up as 'qt.QObject instance' - which is
essentially useless for doing anything with child widgets (for example,
accessing the QWidgetStack of a QTabDialog...)

I consider this being a flaw in the memory management somewhere, because one
should definitely be able to destroy child widgets, leaving everything in a
clean state.

I could send you my code, but it's quite long (2700 lines). I'm going to put
together a
smaller example, which demonstrates the problems I've experienced.


So my ideas:

1. how about letting sip add some kind of conversion constructor to the c++
files ? I mean, one which you can pass a QObject* in, use a large case
statement
with dynamic_cast<SomeQtClass*> with every qt class to get the real class
and
then return the approriately typed python object.

2. No idea, how object destruction works in sip/PyQt, but it should
definitely
be checked. What i would normally expect is, that when loosing the last
reference to Python object, the underlying C++/Qt Object must be deallocated
by
it's destructor. That's also true for objects passed into/connected to the
Qt
framework (subwidgets, for instance).

3. How about some more documentation on sip ...? I mean, i would really like
to
contribute to this work (i'm using it at work) , but it's basically
impossible
because there are way too few lines of comments in the sip source code, and
no
documentation so far. I've got a long experience of C++ programming and am
sure
i am able to contribute somehow.








More information about the PyQt mailing list