Releasing reference to QWidget on closeEvent

Phil Thompson phil at riverbankcomputing.com
Thu Oct 29 17:39:27 GMT 2020


On 29/10/2020 17:33, Julio César Gázquez wrote:
> Hello list.
> 
> I have been doing things like in the sample code below for years.
> Recently I found that using Ubuntu 20.04 package for PyQt5 results in
> a SIGSEGV. It works ok using Phil's wheel package, and also works ok
> using the distro package in older versions of Ubuntu.
> 
> Today, just before filing a bug report to Ubuntu, I found that adding
> a self.deleteLater() call the problem dissappeared.
> 
> So, ¿I should use deleteLater() and did the things wrong the last 8
> years, o it is really a bug in Ubuntu's package?
> 
> from PyQt5.QtWidgets import QWidget, QApplication
> 
> window = None
> 
> class MyWindow(QWidget):
> 
>     def closeEvent(self, event):
> 
>         global window
>         # SIGSEGV if set window to None
>         window = None
>         event.accept()
> 
> 
> app = QApplication([])
> window = MyWindow()
> window.show()
> app.exec_()

You've been lucky for 8 years - use deleteLater().

Phil


More information about the PyQt mailing list