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

Phil Thompson phil at river-bank.demon.co.uk
Tue May 23 16:09:40 BST 2000

Thomas Malik wrote:
> > Now, I'd think calling "del" on some parent would do the right thing.
>  Not feasible in that case: there's essentially no way to remove a page from
> a QTabDialog.
> > > Maybe you can right a small example?
> > >
> Here it goes ...
> untar into a directory and start 'kmyapp'. clicking on the 'kde' toolbar
> button leads to the dialog i've set up. In the first page, you can select a
> 'type' (which was meant to be a graph node's type in the original
> application), the second page should show, per type, a different set of
> 'node properties'. The property sets can be configured in config.py.
> The dialog class is defined in NodePropertyDialog.py, the
> construction/destruction of the property widget sets in PropertyList.py, the
> discrete widgets for the different properties are built together in
> Property.py.
> The 'normal' behaviour (it worked, sort of, until 0.11pre1) is, if you
> select some type on the first page, you can switch to the second page and
> see some lineedits belonging to the type on the first page.
> Now, all the widgets in the second page accumulate, overlapping each other.
> In some parts of the code, i outlined different solution alternatives
> (deleting the frame widget containing the child widgets on the second page,
> using destructors with QWidget.destroy() in the Property subclasses).
> Thomas
>   ------------------------------------------------------------------------
>                     Name: SAMPLE.TAR.gz
>    SAMPLE.TAR.gz    Type: Unix Tape Archive (application/x-tar)
>                 Encoding: base64

The del statements in PropertyList.reset() will only delete the Python
object and not the C++ objects because they are "owned" by C++. Prior to
v0.11 ownership was retained by Python so the del's did what you wanted
- the old behaviour was a bug that didn't show up in Qt v1.x but gives
you a segv every time with Qt v2.x.

So, what to do about it? I can't think of a way to make this transparent
to the programmer. All I can think of at the moment is to implement
/TransferBack/ (ie. transfer ownership back to Python) and add it to
QObject.removeChild(). The following code should then work...

	del self.box

Any other suggestions?


More information about the PyQt mailing list