[RESOLVED] QMainWindow, how to add one Dialog before close, asking if the user really want to close the app?



  • Hello all,

    How can I make something like this?
    I try on override this mehod:

    @protected:
    void closeEvent(QCloseEvent *event);@

    But doesn't works...

    @
    void MainWindow::closeEvent(QCloseEvent *event)
    {
    QMessageBox::StandardButton dialog;
    dialog = QMessageBox::warning(this, "Confirmação de Saida",
    "Deseja realmente sair do Sistema?",
    QMessageBox::Ok | QMessageBox::Cancel);
    if( dialog == QMessageBox::Ok) {
    emit signalSair();
    close();
    }
    }
    @

    But if user choose the option cancel the app closes anyway!
    What should I do?!
    Thanks all!



  • Try event->ignore().



  • Like this:
    @
    void MainWindow::closeEvent(QCloseEvent *event)
    {
    QMessageBox::StandardButton dialog;
    dialog = QMessageBox::warning(this, "Confirmação de Saida",
    "Deseja realmente sair do Sistema?",
    QMessageBox::Ok | QMessageBox::Cancel);
    if( dialog == QMessageBox::Ok) {
    emit signalSair();
    close();
    } else {
    event->ignore();
    }
    }
    @



  • Thanks, works!!!!!!!!!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.