[PyQt] sip: how to make a python instance owned by C++ without using a parent

Mathias.Born at gmx.de Mathias.Born at gmx.de
Mon Aug 27 21:08:13 BST 2012


On 27.08.2012, 22:50:43 Phil Thompson wrote:
> On Sun, 26 Aug 2012 21:11:50 +0200, Mathias.Born at gmx.de wrote:
>> On 26.08.2012, 18:15:55 Phil Thompson wrote:
>>> On Wed, 15 Aug 2012 11:55:47 +0200, Mathias.Born at gmx.de wrote:
>>>> On 15.08.2012, 11:05:42 Phil Thompson wrote:
>>>>> I could change sipTransferTo() to do this if the owner was Py_None.
> At
>>>>> the
>>>>> moment this is undocumented behaviour. Would this be sufficient?
>>>> 
>>>> I believe so.
>> 
>>> Done in hg.
>> 
>> Phil,
>> 
>> First tests show that this works well. It's an important feature, but
>> burried deeply in the documentation, well, actually sort of obscured.
>> 
>> Function "sipConvertToType" is documented as:
>> 
>> If transferObj is NULL then the ownership is unchanged. If it is Py_None
>> then
>> ownership is transferred to Python via a call to sipTransferBack().
>> Otherwise ownership is transferred to C/C++ and obj associated with
>> transferObj via a call to sipTransferTo().
>> 
>> Function "sipTransferTo" tells us:
>> ... If owner is Py_None then obj is given an extra reference which is
>> removed when the C++ instance’s destructor is called. ...
>> 
>> 
>> Since "sipTransferTo" is mentioned by the docs of "sipConvertToType",
> who
>> would guess that Py_None has such a different meaning?
>> 
>> How about adding a corresponding hint to the documentation
>> of "sipConvertToType"?

> I'm not sure that adding documentation to something about what it doesn't
> do makes anything clearer.

> Phil

That's because you are far too familiar with sip :-)

I imagine adding something like

"Note that obj can also be managed by the C++ instance itself, but this
can only be achieved by using sipTransferTo."

to the documentation of "sipConvertToType".

Best Regards,
Mathias Born



More information about the PyQt mailing list