Skip to content

Instantly share code, notes, and snippets.

@fmorency
Created July 9, 2012 19:13
Show Gist options
  • Save fmorency/3078310 to your computer and use it in GitHub Desktop.
Save fmorency/3078310 to your computer and use it in GitHub Desktop.
Destroy Qt widgets properly
import sys
from PySide.QtCore import *
from PySide.QtGui import *
@Slot()
def destroy_slot():
print 'Destroyed'
if __name__ == '__main__':
#Qt boilerplate
app = QApplication(sys.argv)
mw1 = QMainWindow()
mw2 = QMainWindow()
w = QWidget(mw1)
w.destroyed.connect(destroy_slot)
mw1.destroyed.connect(destroy_slot)
mw2.destroyed.connect(destroy_slot)
mw1.show()
mw2.show()
app.exec_()
#Uncomment this to destroy Qt widgets properly
#del mw1
#del mw2
sys.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment