You could emit a signal from widget's closeEvent() handler and connect a slot to that.

Or, if it is a dialog, run it with exec() and put your code after it returns.

Or, if this is the main window, put your code after exec() of the QApplication has returned.

Cheers,
_