Dear list, I am quite puzzled about my piece of code below (and attached), where none of the two destructors is called when terminating the program via closeEvent(). The problem disappears when I remove the assignment "self.main = parent" from MyMenuBar.__init__(). I have checked this on Mac OSX and Ubuntu.
I would actually expect the following to happen with or without the
questionable assignment:
1. The MyMenuBar instance is known as a child of the MyMainWindow instance in
the Qt widget hierarchy. It is thus deleted by Qt on the closeEvent().
2. On deleting that instance its reference self.main disappears, and it cannot
play a role for what happens subsequently.
3. Since the instance of MyWorker lives outside the Qt widget hierarchy, I
would expect its destructor to be called by Python on termination of the
program.
Any clarification is highly appreciated! I am glad to have reduce my way more
complicated situation to that small example, but now I am clueless.
NB: I know that there is a parent() method, and that in that situation the
assignment is pointless etc.
Thomas
#!/usr/bin/env python
import sys
from PySide.QtGui import QApplication
from PySide.QtGui import QMainWindow
from PySide.QtGui import QMenuBar
class MyMainWindow(QMainWindow):
def __init__(self,parent=None):
super(MyMainWindow,self).__init__(parent)
self.worker = MyWorker()
self.setMenuBar(MyMenuBar(self))
self.show()
self.raise_()
class MyMenuBar(QMenuBar):
def __init__(self,parent=None):
super(MyMenuBar,self).__init__(parent)
self.main = parent # This line causes the problem
def __del__(self):
print "in MyMenuBar.__del__()"
class MyWorker(object):
def __del__(self):
print "in MyWorker.__del__()"
app = QApplication(sys.argv)
mainwindow = MyMainWindow()
sys.exit(app.exec_())
--
Dr. habil. Thomas Sturm
Departamento de Matematicas, Estadistica y Computacion
Universidad de Cantabria, Santander, Spain
Avda. Los Castros s/n, Room 1072, +34 693 251058
http://personales.unican.es/sturmt/
#!/usr/bin/env python
import sys
from PySide.QtGui import QApplication
from PySide.QtGui import QMainWindow
from PySide.QtGui import QMenuBar
class MyMainWindow(QMainWindow):
def __init__(self,parent=None):
super(MyMainWindow,self).__init__(parent)
self.worker = MyWorker()
self.setMenuBar(MyMenuBar(self))
self.show()
self.raise_()
class MyMenuBar(QMenuBar):
def __init__(self,parent=None):
super(MyMenuBar,self).__init__(parent)
self.main = parent # This line causes the problem
def __del__(self):
print "in MyMenuBar.__del__()"
class MyWorker(object):
def __del__(self):
print "in MyWorker.__del__()"
app = QApplication(sys.argv)
mainwindow = MyMainWindow()
sys.exit(app.exec_())
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ PySide mailing list [email protected] http://lists.openbossa.org/listinfo/pyside
