I want to shutdown when Ctrl+C is pressed.
fromPyQt5.QtWidgetsimportQMainWindow, QSplitter, QPushButtonfromPyQt5.QtCoreimportQtfromqasyncimportQEventLoop, QApplication, asyncClose, asyncSlotimportsysimportasyncioclassMainWindow(QMainWindow):
def__init__(self, app):
self.app=appsuper().__init__()
self.setWindowTitle("MainWindow")
self.setGeometry(100, 100, 800, 600)
splitter=QSplitter(Qt.Horizontal)
self.setCentralWidget(splitter)
send_button=QPushButton('button')
splitter.addWidget(send_button)
@asyncCloseasyncdefcloseEvent(self, event):
pass@asyncSlot()asyncdefonMyEvent(self):
passdefmain():
app=QApplication(sys.argv)
event_loop=QEventLoop(app)
asyncio.set_event_loop(event_loop)
app_close_event=asyncio.Event()
app.aboutToQuit.connect(app_close_event.set)
main_window=MainWindow(app)
main_window.show()
withevent_loop:
event_loop.run_until_complete(app_close_event.wait())
main()python test.py
Press Ctrl+C and close button.
^CTraceback (most recent call last):
File "/opt/miniconda3/envs/mar/lib/python3.11/site-packages/qasync/__init__.py", line 766, in wrapper
@functools.wraps(fn)
KeyboardInterrupt
[1] 3160831 IOT instruction (core dumped) python src/test.py
pyqt5 5.14.2
qasync 0.27.1
I want to shutdown when Ctrl+C is pressed.
python test.pyPress Ctrl+C and close button.
pyqt5 5.14.2
qasync 0.27.1