[PyQt] How to write handwritten code to access the C++ object when the corresponding python object destroyed?

Weitian Leung weitianleung at gmail.com
Mon Feb 17 14:35:07 GMT 2020


Hi,
    I'm noob in SIP. Say I have two abstract interfaces and one method to
create the object:

struct IUnknown /Abstract/
> {
>     virtual void AddRef() = 0;
>     virtual void Release() = 0;
>
>     %GCClearCode
>         printf("GCClearCode\n");
>     %End
> };
>
> struct IDemo : public IUnknown /Abstract/
> {
>     virtual void SayHi() = 0;
> };
>

void createDemo(IDemo **demo /Out/);
>


Using in python side:
idemo = demo.createDemo()
idemo = None

Is it possible to write some handwritten code that call the Release method
when idemo set to None or when  idemo doing GC?
Or if we can call AddRef automatically when idemo assign to another object.

I known that on python side we can call AddRef/Release to make it works,
but I want the code more python's way.

The %GCClearCode handwritten code never called in this case.
And the %GCTraverseCode handwritten code only call when the object make an
assignment to other object.
Am I missing something?

Please check the full code in the  attached file.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20200217/403652ed/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: demo.zip
Type: application/zip
Size: 1053 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20200217/403652ed/attachment.zip>


More information about the PyQt mailing list