Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    2
    4
    4109
    Loading More Posts
    • 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
      dcbasso last edited by

      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 Reply Quote 0
      • B
        bodzio131 last edited by

        Try event->ignore().

        1 Reply Last reply Reply Quote 0
        • D
          dcbasso last edited by

          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 Reply Quote 0
          • D
            dcbasso last edited by

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

            1 Reply Last reply Reply Quote 0
            • First post
              Last post