[PyKDE] ListViewItems and garbage collection

Jim Bublitz jbublitz at nwinternet.com
Mon Jul 22 08:39:58 BST 2002


On 21-Jul-02 Neil Stevens wrote:
> Well, my items are being created by the ListView itself, and the
> ListView is passing self as the parent, so there is ownership.

<sample snipped - looked good>
 
> So I'm led to believe that QListViewItem has a special trick in
> it.

I whipped up a short example tonight and confirmed the problem.
This is so ridiculously simple it shouldn't be possible to screw up,
however since I *did* screw it up, here's the fix:

In PyKDE-3.2.4/sip/klistview.sip, find the KListViewItem class. For
each KListViewItem constructor change:

   KListViewItem (QListView * ...

to:

   KListViewItem (QListView */TransferThis/ ...

Only add the /TransferThis/ to the *first* QListView pointer in
each constructor (which would be 'parent' in the C++/h file
version). Add /TransferThis/ after the '*' and before any
comma; whitespace is ignored. This effectively tells python that
C++ will manage the object being created (ie transfer the 'this'
pointer).

After the edits do:

   build -mkdeui

and then run make, make install as usual. This will only rebuild
the kdeui code and save compiling all of the other modules. It's
still a 20 minute compile, but better than an hour.

I've also verified that the patched and recompiled code works
correctly. It's also why QListViewItem worked correctly.
 
> thanks for any help,

Sorry I couldn't check this more thoroughly earlier - I only had a
KDE2.1.1 version up this morning and KListViewItem didn't exist
until 2.2.0 (which is why my app uses QListViewItem instead). The
sip file is the same (versioned), but I didn't see the error
immediately.


Jim




More information about the PyQt mailing list