0

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?

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Frac
  • 321
  • 5
  • 13
  • 1
    remove `app.exec()`. Also provide a [mre] – eyllanesc May 08 '22 at 02:24
  • Yes, this works. For trying to figure out why, I took a look at this thread: https://stackoverflow.com/questions/23142719/pyqt-app-exec-stops-all-following-code-from-running It seems that app.exec() runs the event loop also. In my code, I pulled out the event loop so asyncio and Qt could share it (i think) which means I was running it twice. – Frac May 08 '22 at 17:12

0 Answers0