Issue
Here is what I have, from a garbage-collection/proper cleanup perspective:
class MyWidget(QWidget):
def __init__(self,qtParent):
QWidget.__init__(self,qtParent):
self.mySubWidget = MySubWidget(self) # <-- keeping a direct reference to the child
When I destroy MyWidget, will mySubWidget also get correctly destroyed by Qt/pyside/python when I call the code below?
setAttribute( Qt.DeleteOnClose, True)
myWidget.close()
Or, should I use weakrefs like below?
import weakref
class MyWidget(QWidget):
def __init__(self,qtParent):
QWidget.__init__(self,qtParent):
self.mySubWidget = weakref.ref(MySubWidget(self))
Solution
The first one is fine. If you don't have any other reference to the created MySubWidget
outside of your instance, then it will be garbage collected when you delete the MyWidget
instance.
Answered By - Avaris
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.