I have an application I am working on which has a Qt GUI made to control a gRPC back end. I prefer using python-betterproto to process the gRPC .proto files, however these classes use asyncio. After a lot of searching, the only solution I found that allows my Qt Application Class to send signals back and forth between my backend application class was
- have my backend class inherit from QtCore.QObject
- use QEventLoop and asyncSlot from asyncqt
- and launch the application as follows
app = QtWidgets.QApplication(sys.argv)
loop = QEventLoop(app)
asyncio.set_event_loop(loop)
window = Ui()
app.exec()
with loop:
loop.run_forever()
The application is working, and signals can be connected to slots in both directions. However, when I close the GUI Window, the application is still running, I assume because I told the loop to 'run_forever()'
How can I make this event loop stop listening when the application closes?