[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] causes self to be owned by Qt instead of PyQt ???
From:       redstone-cold <redstone-cold () 163 ! com>
Date:       2015-04-01 6:32:19
Message-ID: 3af3b169.144.14c73ae3643.Coremail.redstone-cold () 163 ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]

[Attachment #4 (text/plain)]

1)"The parent argument, if not None, causes self to be owned by Qt instead of PyQt", \
does owned by PyQt also mean the object owned by Python ? If it is true ,then another \
question below 


2)In the doc of sip.setdestroyonexit(destroy) says, "Calling this function with a \
value of False disables the automatic destruction of C++ instances and C \
structures(owned by Python)." ,then which is responsible for destroying these C++ \
instances and C structures? the dtor of them ?


3)In the doc of sip.setdestroyonexit(destroy) says,"When the Python interpreter exits \
it garbage collects those objects that it can. This means that any corresponding C++ \
instances and C structures owned by Python are destroyed. Unfortunately this happens \
in an unpredictable order and so can cause memory faults within the wrapped library. \
" 


"since Python does not guarantee that objects will be deleted in a specific order \
when it exits. On the other hand, when Qt deletes an object, it always tries to \
delete all its children as well, which will normally ensure that objects get deleted \
in the right order. This is especially important when Qt takes ownership of an \
object, because you could end up in a situation where an attempt is made to delete \
the object twice (which will result in a crash)." quoted from here \
http://stackoverflow.com/questions/27131294/error-qobjectstarttimer-qtimer-can-only-be-used-with-threads-started-with-qt



Since Qt ensure that objects get deleted in the right order, so is it better to let \
the parent argument not be None, thus causes self to be owned by Qt instead of PyQt? \
or just set sip.setdestroyonexit(False) ?


4) When I Wrapped the if __name__ == '__main__': part in a function main(),the issue \
went away ,can you explain why ? changed version https://bpaste.net/show/36c594a1c82e








在2015年03月30 18时32分, "Phil Thompson"<phil@riverbankcomputing.com>写道:

On 30/03/2015 11:15 am, redstone-cold wrote:
> In the QObject.__init__(self, Parent=None) documentation it states:
> 
> The parent argument, if not None, causes self to be owned by Qt instead
> of PyQt.
> 
> What does it mean to be owned by Qt instead of PyQt? Does this have
> effects on behavior that I should be aware of when developing a PyQt
> application?

It means that Qt will call the dtor of the C++ instance when necessary
and it may still exist even if the Python object that wraps it is
garbage collected. Generally you don't need to worry about it.

Phil
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com


[Attachment #5 (text/html)]

<div><div><div>1)"The parent argument, if not None, causes self to be owned by Qt \
instead of PyQt", does owned by PyQt also mean the object owned by Python \
?</div><div>If it is true ,then another question \
below&nbsp;</div><div><br></div><div>2)In the doc of sip.setdestroyonexit(destroy) \
says, "Calling this function with a value of False disables the automatic destruction \
of C++ instances and C structures(owned by Python)." ,then which is responsible for \
destroying these C++ instances and C structures? the dtor of them \
?</div><div><br></div><div>3)In the doc of sip.setdestroyonexit(destroy) says,"When \
the Python interpreter exits it garbage collects those objects that it can. This \
means that any corresponding C++ instances and C structures owned by Python are \
destroyed. Unfortunately this happens in an unpredictable order and so can cause \
memory faults within the wrapped library. "&nbsp;</div><div><br></div><div>"since \
Python does not guarantee that objects will be deleted in a specific order when it \
exits. On the other hand, when Qt deletes an object, it always tries to delete all \
its children as well, which will normally ensure that objects get deleted in the \
right order. This is especially important when Qt takes ownership of an object, \
because you could end up in a situation where an attempt is made to delete the object \
twice (which will result in a crash)." quoted from here \
http://stackoverflow.com/questions/27131294/error-qobjectstarttimer-qtimer-can-only-be-used-with-threads-started-with-qt</div><div><br></div><div>Since \
Qt ensure that objects get deleted in the right order, so is it better to let the \
parent argument not be None, thus causes self to be owned by Qt instead of PyQt? or \
just set sip.setdestroyonexit(False) ?</div><div><br></div><div>4) When I Wrapped the \
if __name__ == '__main__': part in a function main(),the issue went away ,can you \
explain why ? changed version https://bpaste.net/show/36c594a1c82e</div></div><div \
style="color: rgb(0, 0, 0); font-family: arial; font-size: 14px;"><br></div><div \
style="color: rgb(0, 0, 0); font-family: arial; font-size: 14px;"><br></div><div \
style="color: rgb(0, 0, 0); font-family: arial; font-size: 14px;"><br></div><div \
style="color: rgb(0, 0, 0); font-family: arial; font-size: \
14px;"><br></div></div><!-- jy5ContentSuffix --><div>在2015年03月30 18时32分, \
"Phil Thompson"&lt;phil@riverbankcomputing.com&gt;写道:</div><blockquote \
id="isReplyContent" style="padding-left:1ex; margin: 0px 0px 0px 0.8ex; BORDER-LEFT: \
#ccc 1px solid"><br>On 30/03/2015 11:15 am, redstone-cold wrote:<br>&gt; In the \
QObject.__init__(self, Parent=None) documentation it states:<br>&gt; <br>&gt; The \
parent argument, if not None, causes self to be owned by Qt instead <br>&gt; of \
PyQt.<br>&gt; <br>&gt; What does it mean to be owned by Qt instead of PyQt? Does this \
have<br>&gt; effects on behavior that I should be aware of when developing a \
PyQt<br>&gt; application?<br><br>It means that Qt will call the dtor of the C++ \
instance when necessary <br>and it may still exist even if the Python object that \
wraps it is <br>garbage collected. Generally you don't need to worry about \
it.<br><br>Phil<br>_______________________________________________<br>PyQt mailing \
list &nbsp; &nbsp;<a \
href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a><br></blockquote><br><br><span \
title="neteasefooter"><span id="netease_mail_footer"></span></span>


[Attachment #6 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic