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))
The first one is fine. If you don’t have any other reference to the created
MySubWidgetoutside of your instance, then it will be garbage collected when you delete theMyWidgetinstance.