Pyqt5: closeEvent does not terminate application if using Twisted reactor

时间:2018-09-19 08:16:32

标签: python pyqt pyqt5 twisted

closeEvent method is executed (I can see thanks to the log), the appWindow hides, but the application does not end: is kept open in the console where it was launched.

Code:

#!/usr/bin/python3
# -*- coding: utf-8 -*-
from PyQt5.QtWidgets import QApplication, QMainWindow
import sys
app = QApplication(sys.argv)
import qt5reactor
qt5reactor.install()
from twisted.internet import reactor
from twisted.python import log


class AppWindow(QMainWindow):

    def __init__(self, reactor):
        super().__init__()
        self.reactor = reactor
        self.setObjectName('AppWindow')
        self.initUI()

    def initUI(self):
        self.resize(1200, 700)
        self.show()

    def closeEvent(self, e):
        log.msg("Close app event")
        self.reactor.stop()
        e.accept()

# Create window and run reactor
log.startLogging(sys.stdout)
win = AppWindow(reactor)
reactor.run()

0 个答案:

没有答案