[PyQt] how does sip detect when an object has been deleted by C++

Nathan Cournia cournia at gmail.com
Wed Mar 17 03:57:14 GMT 2010


I've just started using SIP and have run into some questions.  First, given
the following pseudo sip code:

struct Foo
#include <Foo.h>

    void bar();

// basically does "return new Foo;"
Foo* createFoo()

// basically does "delete foo;"
deleteFoo(Foo* foo /Transfer/);

Now let's look at some pseudo python code:

# creates a Foo* object
a = createFoo()

# deletes the created Foo* object

# returns false

# crash

I would have expected sip.isdeleted(a) to return true.

If I modify the definition of Foo to inherit from QObject like so:

struct Foo: QObject
#include <Foo.h>

     void bar();

with Foo inheriting from QObject, the code above will return true at
sip.isdeleted(a).  Neat!

Which brings me to my question: How does SIP detect that the C++ code in
deleteFoo() deleted the QObject inherited Foo object?  Could you point me to
the code which does this detection?  I've looked over the documentation and
source code, but haven't found anything describing the actual mechanism.

My hope is to understand how this detection works, and possibly use
something similar to track when objects are deleted without having to
inherit from QObject.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100316/203ae84d/attachment.html>

More information about the PyQt mailing list