[PyQt] causes self to be owned by Qt instead of PyQt ???
redstone-cold
redstone-cold at 163.com
Wed Apr 1 07:32:19 BST 2015
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 at 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 at riverbankcomputing.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150401/de53fd96/attachment-0001.html>
More information about the PyQt
mailing list