Different behaviour finishing an application in pyqt5 - pyqt6

Gottfried Müller gottfried.mueller at gmx.de
Tue Mar 22 11:02:05 GMT 2022


Hello,

the follwing example shows a different behaviour in pyqt5 and pyqt6. I
did not found the reason. In pyqt5 after pressing the exit menu the
function "confirmClose" is called once, in pyqt6 twice. Closing the
application window does not show this effect. I wonder I am using
QApplication.quit but I did not find it in the Qt documentations and I
get no error. Substitute QApplication.quit with sys.exit has the same
different effect.
I am using manjaro pyt6.2.3, pyqt5.15.6, qt 6.2.3, qt.5.13

import sys
from PyQt6.QtWidgets import QApplication, QWidget, QPushButton, QMenu,
QVBoxLayout

class ApplWindow(QWidget):
     def __init__(self, parent=None):
         super().__init__(parent=parent)
         btn = QPushButton("Appl menu", parent=self)
         menu = QMenu(parent=self)
         exitProg = menu.addAction("Exit program")
         exitProg.triggered.connect(self.confirmClose)
         btn.setMenu(menu)
         layout = QVBoxLayout()
         layout.addWidget(btn)
         self.setLayout(layout)

     def closeEvent(self, event):
         self.confirmClose()
         event.ignore()

     def confirmClose(self):
         print("close confirmed")
         QApplication.quit()

def main():
     appl = QApplication(sys.argv)
     applWindow = ApplWindow()
     applWindow.show()
     return appl.exec()


if __name__ == "__main__":
     main()


More information about the PyQt mailing list