before a window is closed QWidget::closeEvent() is called. This maybe fit your needs, or say what exactly you want achieve.