Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [RESOLVED] QMainWindow, how to add one Dialog before close, asking if the user really want to close the app?

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

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 4.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dcbasso
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bodzio131
      wrote on last edited by
      #2

      Try event->ignore().

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dcbasso
        wrote on last edited by
        #3

        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();
        }
        }
        @

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dcbasso
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved