[PyQt] How to write handwritten code to access the C++ object when the corresponding python object destroyed?
Weitian Leung
weitianleung at gmail.com
Wed Feb 19 05:55:15 GMT 2020
Thanks, it works!
On Wednesday, February 19, 2020, Phil Thompson <phil at riverbankcomputing.com>
wrote:
> On 17/02/2020 14:35, Weitian Leung wrote:
>>
>> 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.
>
>
https://www.riverbankcomputing.com/static/Docs/sip/c_api.html#event-handlers
>
> I've only just realised that that documentation is incomplete. The two
event types currently implemented are...
>
> sipEventWrappedInstance, /* After wrapping a C/C++ instance. */
> sipEventCollectingWrapper, /* When garbage collecting a wrapper object.
*/
>
> ...and the corresponding event handler signatures are...
>
> typedef void (*sipWrappedInstanceEventHandler)(void *sipCpp);
> typedef void (*sipCollectingWrapperEventHandler)(sipSimpleWrapper
*sipSelf);
>
> Phil
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20200219/25a6008a/attachment.html>
More information about the PyQt
mailing list