I would like to display a message before QGIS close. But I can't intercept the closeEvent of the main window from my plugin. I've tested this code which doesn't work.
# Main method
QgsApplication.instance().closeEvent = self.mainWindowCloseEvent
def mainWindowCloseEvent(self, event) :
# displaying message...
event.ignore()
QgsApplication
class inherits fromQApplication
which has the signalaboutToQuit()
. Perhaps you can make that work for you?aboutToQuit
might do the trick, maybe with something like:QgsApplication.instance().aboutToQuit.connect(mainWindowCloseEvent)
, similar to how you connect qt signals to function in the plugin.