1

I am developing a Python application and I open ports using uPnP. The problem is that when the application is forced to be closed by process, the port is still opened. So I'm searching for an event in PyQt (or something else) to do some actions when the process is closing. Be sure that I'm not talking about the close button.

1 Answer 1

2

QApplications aboutToQuit signal appears to be built exactly for this purpose. Simply add a slot to your code and connect to this signal. Your slot should be notified before the application quits.

From the pyQT docs:

This signal is emitted when the application is about to quit the main event loop, e.g. when the event loop level drops to zero. This may happen either after a call to quit() from inside the application or when the users shuts down the entire desktop session.

The signal is particularly useful if your application has to do some last-second cleanup. Note that no user interaction is possible in this state.

(emphasis mine)

3
  • Sorry, this is not worked, i did that : QtCore.QObject.connect(MainWindow, QtCore.SIGNAL('aboutToQuit()'), self.exit) ; where MainWindow is QMainWindow, and self.exit is a function who prints some text. :/
    – Extaze
    Commented Mar 30, 2012 at 20:15
  • @Extaze aboutToQuit is when the program is about to quit, not the main window. To use aboutToQuit you need to connect to your QApplication's aboutToQuit signal.
    – Doug T.
    Commented Mar 31, 2012 at 14:37
  • QtCore.QObject.connect(app, QtCore.SIGNAL('aboutToQuit()'), ui.exit) still not work ...
    – Extaze
    Commented Mar 31, 2012 at 18:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.