0

I'm opening a dialog that presents a form to the user with:

 if(dialog.exec() == QDialog::Accepted)
    {
        // do stuff based on returned values

      if (retval == 1)
        {
          value1=dialog.value1();

         }

   if (retval == 2)
        {
          // do something else with values from dialog
         }
     }

The form's buttons offer several choices for manipulating the data the user enters. The user may well want to do more than one thing with the data on the form. Is there a way to keep the dialog open until the reject() signal is passed by the dialog's cancel button?

I want the dialog to stay open until it is explicitly closed via the cancel button. I want the other buttons to function as they currently do, pass values back to the function that opened the dialog, but I want those values passed without closing the dialog.

ymoreau
  • 3,402
  • 1
  • 22
  • 60
Jocala
  • 243
  • 1
  • 4
  • 16
  • Your question is not so clear, you mean than exec() is exiting when you do not want to, for example when you press OK button you want it to remain open and close only on the cancel click? – Marco Feb 10 '15 at 22:11
  • Edited, hopefully for clarity. – Jocala Feb 10 '15 at 22:28
  • My first instinct when reading this question is, that this sounds like a bad idea. Of course I don't know what you are doing, but I guess there is probably a better solution to your problem than misusing UI gadgets to a purpose they weren't designed for. The user expects the dialog to disappear when clicking on OK. – Misch Feb 10 '15 at 22:43
  • Edited again to reflect that the dialog is a form, not a OK/Cancel dialog. – Jocala Feb 10 '15 at 22:58

1 Answers1

0

It looks like you are using a Dialog when you don't really need one. Anyway if you really need the dialog behavior, you can override some methods on your QDialog :

//Prevent window been closed
void MyDialog::closeEvent(QCloseEvent *event) {
    event->ignore(); 
}
void MyDialog::accept() {    
    //default implementation would call: done(QDialog::Accepted)

    //you can emit some signal
}

Keep in mind that exec() wont return until you close the dialog, pressing reject or calling done(). You can pass more information from the dialog emiting signals from it.

Smasho
  • 1,170
  • 8
  • 19
  • So, if I understand correctly what I really need to do is open a new window with my form and dismiss it when I'm done? Not use a dialog? – Jocala Feb 10 '15 at 23:32
  • Correct. If what you want is your window to be modal, you can just use [windowModality](http://qt-project.org/doc/qt-4.8/qwidget.html#windowModality-prop). – Smasho Feb 11 '15 at 00:06