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. Keep a dialog open until reject()
Forum Updated to NodeBB v4.3 + New Features

Keep a dialog open until reject()

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 1.6k Views 1 Watching
  • 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.
  • J Offline
    J Offline
    jocala
    wrote on last edited by
    #1

    I'm opening a dialog 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
             }
         }
    

    @

    Is there a way to keep the dialog open until the reject() signal is passed by the dialog's cancel button?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Do you mean something like using a while loop until the user cancels the dialog ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jocala
        wrote on last edited by
        #3

        Would a do/while loop be the way? Would looping the exec repaint the dialog each time the loop cycled?

        The dialog is a form, 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. Now, they have to re-open the dialog after each action. That's fine if they only wanted to do that one thing, but that's not always the case

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then are you sure that returning from the dialog is the right way to interact with your users ?

          You could use an "Apply" button that will trigger a slot that parses your dialog contents thus it would avoid needing to close it each time or use a loop.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • A Offline
            A Offline
            alex_malyu
            wrote on last edited by
            #5

            Sometimes you simply do not need apply. you want action to be executed if everything is right, but want user to fix wrong input first
            Often you can achieve this with validators.
            But you do not have to.
            Subclassing is usually a key to everything when you dial with good designed code in C++.

            In your case you could override and do all the checks in
            void QDialog::done(int r)

            Original:

            • hides dialog
            • set results
            • emits some signals

            So in your version can call it only if user either rejected or everything is right.

            @void MyDialog::done(int r)
            {
            bool canClose = true;

            if ( QDialog::Accepted )
            {
                  ... do whatever you need 
            
                   ... if can't close yet , for example
                   .... user accepted but data he entered was invalid set
            
                  canClose = false;
            }
            
            if (canClose)
                  QDialog::done(r);
            

            }
            @

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jocala
              wrote on last edited by
              #6

              Thank you for the thoughts. Someone else suggested that instead of using a dialog for a form, I should consider using a new window and just keep it open until I'm done with it. Lost to think about here, my only QT code has been single-window only.

              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