0

I want to have my app save data before closing itself. I can have the user use the quit button (I made myself) that is connected to a function. But I don't know how to call the function when the user closes the app native close button.

Screenshot

Is there a way to call a function when the user uses the close button as mentioned in the screenshot above? Thank you for your time in advance. :)

Ali
  • 39
  • 4

1 Answers1

0

This question has 2 answers that can help you

Most common way would be:

class MainWidget(QtWidgets.QWidget):

    #...

    def closeEvent(self, event):
        print "closing PyQtTest"
        self.SaveSettings()
        # report_session()

Or atexit module of the standard Python.

pedro_bb7
  • 1,601
  • 3
  • 12
  • 28