How to get the closed sub-window from within the CloseEvent method.

  • I have the following application:


    The CloseEvent method code:

    void PSubWindow::closeEvent(QCloseEvent *event) {
        if(this->property("isSaved").toBool() == false){
            if(QMessageBox::warning(this->parent, "Changes not saved", "Would you like to save the modifiction?", QMessageBox::Yes|QMessageBox::No) == QMessageBox::Yes){

    I want to get the closed sub-window before destroyed from within CloseEvent method to save the textual contents of that window because when closing a sub-window without to be it is the active sub-window, it saves another sub-window content.

  • Lifetime Qt Champion


    QTabWidget::tabCloseRequested might be of interest.

    Hope it helps.

  • Thank you, but I want two features (prevent the closing + get the closed window), but QTabWidget::tabCloseRequested does not have the two features.

  • Lifetime Qt Champion

    Then you'll likely have to subclass QTabWidget/QTabBar to fit your needs.

  • I think I found a suitable function called eventFilter(QObject *watched, QEvent *event).
    Do you think that function is suitable too?

  • Lifetime Qt Champion

    Yes, that could also be an alternative.

Log in to reply