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. " QDialog::Accepted" is doesn't work.
Forum Updated to NodeBB v4.3 + New Features

" QDialog::Accepted" is doesn't work.

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 3 Posters 3.1k Views 2 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.
  • Pl45m4P Pl45m4

    @JonB said in " QDialog::Accepted" is doesn't work.:

    So far as I can see, this is not the important part :)

    Without the call of close() there would be no topic :)
    Then OP would have had to figure out in another way, why (or that) the dialog never reaches Accepted status through the buttonBox :)

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by JonB
    #6

    @Pl45m4
    I do not follow what you are saying at all. I do not think the close() is relevant. I do not think the OP's dlg->exec() returns, for the reason I have suggested and the remedy required. Do you know that his exec() does return?

    Of course if people would please not write
    @MyNameIsQt said in " QDialog::Accepted" is doesn't work.:

    But this doesn't work.

    and make readers have to guess what they might mean/see/not see, answering would be a lot easier....

    Pl45m4P 1 Reply Last reply
    0
    • JonBJ JonB

      @Pl45m4
      I do not follow what you are saying at all. I do not think the close() is relevant. I do not think the OP's dlg->exec() returns, for the reason I have suggested and the remedy required. Do you know that his exec() does return?

      Of course if people would please not write
      @MyNameIsQt said in " QDialog::Accepted" is doesn't work.:

      But this doesn't work.

      and make readers have to guess what they might mean/see/not see, answering would be a lot easier....

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #7

      @JonB said in " QDialog::Accepted" is doesn't work.:

      Do you know that his exec() does return?

      No, it does not. At least not from the code we can see. Maybe when the progress bar hits 100%, you never know :)

      @MyNameIsQt
      show() + exec() is also redundant and these are two different approaches.
      show() just shows the widget / makes it visible, while exec() creates its own, blocking event loop.

      To call your dialog, you dont need more than this.

      ProgressDlg *dlg = new ProgressDlg(this);
          dlg->setAttribute(Qt::WA_DeleteOnClose);
          dlg->setMessage("Saving .Wpub Files");
          dlg->open();
      

      and in your dialog code something like

      connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
      connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
      

      or play with the QDialogButtonRoles
      ( https://doc.qt.io/qt-6/qdialogbuttonbox.html#StandardButton-enum)

      @JonB, I just realized that the connect isn't necessarily needed. If these buttons are StandardButtons like QDialogButtonBox::Ok, which already has the AcceptRole and therefore triggers QDialog::Accept on click.


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      JonBJ 1 Reply Last reply
      0
      • Pl45m4P Pl45m4

        @JonB said in " QDialog::Accepted" is doesn't work.:

        Do you know that his exec() does return?

        No, it does not. At least not from the code we can see. Maybe when the progress bar hits 100%, you never know :)

        @MyNameIsQt
        show() + exec() is also redundant and these are two different approaches.
        show() just shows the widget / makes it visible, while exec() creates its own, blocking event loop.

        To call your dialog, you dont need more than this.

        ProgressDlg *dlg = new ProgressDlg(this);
            dlg->setAttribute(Qt::WA_DeleteOnClose);
            dlg->setMessage("Saving .Wpub Files");
            dlg->open();
        

        and in your dialog code something like

        connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
        connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
        

        or play with the QDialogButtonRoles
        ( https://doc.qt.io/qt-6/qdialogbuttonbox.html#StandardButton-enum)

        @JonB, I just realized that the connect isn't necessarily needed. If these buttons are StandardButtons like QDialogButtonBox::Ok, which already has the AcceptRole and therefore triggers QDialog::Accept on click.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #8

        @Pl45m4 said in " QDialog::Accepted" is doesn't work.:

        @JonB just realized that the connect isn't necessarily needed. If these buttons are StandardButtons like QDialogButtonBox::Ok, which already has the AcceptRole and therefore triggers QDialog::Accept on click.

        Then please explain why https://doc.qt.io/qt-6/qdialogbuttonbox.html#details has the following explanation plus code:

        Alternatively, QDialogButtonBox provides several standard buttons (e.g. OK, Cancel, Save) that you can use. They exist as flags so you can OR them together in the constructor.

            buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
                                             | QDialogButtonBox::Cancel);
        
            connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
            connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
        

        ? TBH I am getting a bit tired of answering the same each time. I have already said that QDialogButtonBox::accepted is a dialogbuttonbox signal, and is not the same as QDialog::accepted() (signal) or QDialog::accept() (slot), which is why I typed it all in. Unless you know better.

        Pl45m4P M 2 Replies Last reply
        0
        • JonBJ JonB

          @Pl45m4 said in " QDialog::Accepted" is doesn't work.:

          @JonB just realized that the connect isn't necessarily needed. If these buttons are StandardButtons like QDialogButtonBox::Ok, which already has the AcceptRole and therefore triggers QDialog::Accept on click.

          Then please explain why https://doc.qt.io/qt-6/qdialogbuttonbox.html#details has the following explanation plus code:

          Alternatively, QDialogButtonBox provides several standard buttons (e.g. OK, Cancel, Save) that you can use. They exist as flags so you can OR them together in the constructor.

              buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
                                               | QDialogButtonBox::Cancel);
          
              connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
              connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
          

          ? TBH I am getting a bit tired of answering the same each time. I have already said that QDialogButtonBox::accepted is a dialogbuttonbox signal, and is not the same as QDialog::accepted() (signal) or QDialog::accept() (slot), which is why I typed it all in. Unless you know better.

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by Pl45m4
          #9

          @JonB said in " QDialog::Accepted" is doesn't work.:

          I have already said that QDialogButtonBox::accepted is a dialogbuttonbox signal, and is not the same as QDialog::accepted() (signal) or QDialog::accept() (slot), which is why I typed it all in. Unless you know better.

          I dont know better, but I just checked the documentation and found this :)
          [Edit: QDialogButtonBox signal mistaken for QDialog]

          When a button is clicked in the button box, the clicked() signal is emitted for the actual button is that is pressed. For convenience, if the button has an AcceptRole, RejectRole, or HelpRole, the accepted(), rejected(), or helpRequested() signals are emitted respectively.

          ( https://doc.qt.io/qt-6/qdialogbuttonbox.html#details)

          And AFAIK these Roles are applied automatically if you create a buttonBox in Designer.
          [ Edit: Yes, but only the buttonBox ones... :) ]

          I'm also confused right now :D

          BTW: @MyNameIsQt sorry for discussing in your topic :)
          If you need the if (dlg->exec() == QDialog::Accepted)-check only to call close(), you can remove it.
          Then it's up to you whether you move from exec() to dlg->open().
          After that, check if the signals are still not emitted.


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          JonBJ 1 Reply Last reply
          0
          • Pl45m4P Pl45m4

            @JonB said in " QDialog::Accepted" is doesn't work.:

            I have already said that QDialogButtonBox::accepted is a dialogbuttonbox signal, and is not the same as QDialog::accepted() (signal) or QDialog::accept() (slot), which is why I typed it all in. Unless you know better.

            I dont know better, but I just checked the documentation and found this :)
            [Edit: QDialogButtonBox signal mistaken for QDialog]

            When a button is clicked in the button box, the clicked() signal is emitted for the actual button is that is pressed. For convenience, if the button has an AcceptRole, RejectRole, or HelpRole, the accepted(), rejected(), or helpRequested() signals are emitted respectively.

            ( https://doc.qt.io/qt-6/qdialogbuttonbox.html#details)

            And AFAIK these Roles are applied automatically if you create a buttonBox in Designer.
            [ Edit: Yes, but only the buttonBox ones... :) ]

            I'm also confused right now :D

            BTW: @MyNameIsQt sorry for discussing in your topic :)
            If you need the if (dlg->exec() == QDialog::Accepted)-check only to call close(), you can remove it.
            Then it's up to you whether you move from exec() to dlg->open().
            After that, check if the signals are still not emitted.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #10

            @Pl45m4
            My friend, one more time, I have already written this several times! Please read what I have written, then I don't have to keep typing the same thing! Those are QDialogButtonBox signals, which IS NOT THE SAME as QDialog signals. Signals on different objects which happen to have the same name, like, accepted(). I really don't know how much clearer I can be. QDialogButtonBox::accepted() signal does NOT raise/emit QDialog::accepted() signal. That is precisely why the example shows having to attach QDialogButtonBox::accepted() (signal) -> QDialog::accept() (slot) -> QDialog::accepted() (signal).

            If you don't think so why don't you try code with a QDialogButtonBox but without the connect()s, then you/we will know?

            Pl45m4P 1 Reply Last reply
            3
            • JonBJ JonB

              @Pl45m4 said in " QDialog::Accepted" is doesn't work.:

              @JonB just realized that the connect isn't necessarily needed. If these buttons are StandardButtons like QDialogButtonBox::Ok, which already has the AcceptRole and therefore triggers QDialog::Accept on click.

              Then please explain why https://doc.qt.io/qt-6/qdialogbuttonbox.html#details has the following explanation plus code:

              Alternatively, QDialogButtonBox provides several standard buttons (e.g. OK, Cancel, Save) that you can use. They exist as flags so you can OR them together in the constructor.

                  buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
                                                   | QDialogButtonBox::Cancel);
              
                  connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
                  connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
              

              ? TBH I am getting a bit tired of answering the same each time. I have already said that QDialogButtonBox::accepted is a dialogbuttonbox signal, and is not the same as QDialog::accepted() (signal) or QDialog::accept() (slot), which is why I typed it all in. Unless you know better.

              M Offline
              M Offline
              MyNameIsQt
              wrote on last edited by MyNameIsQt
              #11

              @JonB Thanks so much.
              This is work!

              ProgressDlg::ProgressDlg(QWidget *parent)
                  : QDialog(parent)
                  , ui(new Ui::ProgressDlg)
                  , m_canceled(false)
              {
                  ui->setupUi(this);
              
                  ui->progressBar->setRange(0, 100);
                  ui->progressBar->setValue(0);
              
              //    ui->buttonBox->setEnabled(false);
              
                  connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
                  connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
              }
              
              ....
              void WebpEditor::on_actionProgress_triggered()
              {
                  ProgressDlg *dlg = new ProgressDlg(this);
                  dlg->setAttribute(Qt::WA_DeleteOnClose);
                  dlg->setMessage("Saving .Wpub Files");
                  dlg->show();
              
                  if (dlg->exec() == QDialog::Accepted) {
                      dlg->close();
                  }
              }
              
              

              It's not Problem of QDialogButtonBox; :)
              Thanks so much. and @Pl45m4 Thanks too.

              M JonBJ 2 Replies Last reply
              3
              • M MyNameIsQt has marked this topic as solved on
              • M MyNameIsQt

                @JonB Thanks so much.
                This is work!

                ProgressDlg::ProgressDlg(QWidget *parent)
                    : QDialog(parent)
                    , ui(new Ui::ProgressDlg)
                    , m_canceled(false)
                {
                    ui->setupUi(this);
                
                    ui->progressBar->setRange(0, 100);
                    ui->progressBar->setValue(0);
                
                //    ui->buttonBox->setEnabled(false);
                
                    connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
                    connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
                }
                
                ....
                void WebpEditor::on_actionProgress_triggered()
                {
                    ProgressDlg *dlg = new ProgressDlg(this);
                    dlg->setAttribute(Qt::WA_DeleteOnClose);
                    dlg->setMessage("Saving .Wpub Files");
                    dlg->show();
                
                    if (dlg->exec() == QDialog::Accepted) {
                        dlg->close();
                    }
                }
                
                

                It's not Problem of QDialogButtonBox; :)
                Thanks so much. and @Pl45m4 Thanks too.

                M Offline
                M Offline
                MyNameIsQt
                wrote on last edited by MyNameIsQt
                #12

                @MyNameIsQt Wow Sorry
                This is it.

                if (dlg->exec() == QDialog::Accepted) {
                        ...
                 }
                

                not this

                if (dlg->exec() == QDialog::Accepted) {
                       dlg->close();   // "close()" is don't need it...
                 }
                
                1 Reply Last reply
                2
                • M MyNameIsQt

                  @JonB Thanks so much.
                  This is work!

                  ProgressDlg::ProgressDlg(QWidget *parent)
                      : QDialog(parent)
                      , ui(new Ui::ProgressDlg)
                      , m_canceled(false)
                  {
                      ui->setupUi(this);
                  
                      ui->progressBar->setRange(0, 100);
                      ui->progressBar->setValue(0);
                  
                  //    ui->buttonBox->setEnabled(false);
                  
                      connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
                      connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
                  }
                  
                  ....
                  void WebpEditor::on_actionProgress_triggered()
                  {
                      ProgressDlg *dlg = new ProgressDlg(this);
                      dlg->setAttribute(Qt::WA_DeleteOnClose);
                      dlg->setMessage("Saving .Wpub Files");
                      dlg->show();
                  
                      if (dlg->exec() == QDialog::Accepted) {
                          dlg->close();
                      }
                  }
                  
                  

                  It's not Problem of QDialogButtonBox; :)
                  Thanks so much. and @Pl45m4 Thanks too.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #13

                  @MyNameIsQt
                  I am still worried by your code.

                  • dlg->show(); prior to dlg->exec() is not necessary, but not harmful.

                  • The dlg->close() after dlg->exec() worries me because you previously set dlg->setAttribute(Qt::WA_DeleteOnClose);. When the user accepts the dialog it is going to get deleted by the exec() finishing. But you still go dlg->close(); on dlg which might have been deleted by then, and that would cause a problem. It may work because the Qt::WA_DeleteOnClose actually calls dlg->deleteLater() rather than delete dlg, I don't know. If it were me I would remove the dlg->close() and verify the dialog still closes on return from exec(), and leave it at that.

                  UPDATE
                  I think you have just posted your latest code above with this removed, good!

                  1 Reply Last reply
                  2
                  • JonBJ JonB

                    @Pl45m4
                    My friend, one more time, I have already written this several times! Please read what I have written, then I don't have to keep typing the same thing! Those are QDialogButtonBox signals, which IS NOT THE SAME as QDialog signals. Signals on different objects which happen to have the same name, like, accepted(). I really don't know how much clearer I can be. QDialogButtonBox::accepted() signal does NOT raise/emit QDialog::accepted() signal. That is precisely why the example shows having to attach QDialogButtonBox::accepted() (signal) -> QDialog::accept() (slot) -> QDialog::accepted() (signal).

                    If you don't think so why don't you try code with a QDialogButtonBox but without the connect()s, then you/we will know?

                    Pl45m4P Offline
                    Pl45m4P Offline
                    Pl45m4
                    wrote on last edited by
                    #14

                    @JonB said in " QDialog::Accepted" is doesn't work.:

                    Signals on different objects which happen to have the same name, like, accepted(). I really don't know how much clearer I can be. QDialogButtonBox::accepted() signal does NOT raise/emit QDialog::accepted() signal

                    @JonB ... whoops :o)
                    a

                    @MyNameIsQt Yes, the new version looks much better :)


                    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                    ~E. W. Dijkstra

                    JonBJ 1 Reply Last reply
                    1
                    • Pl45m4P Pl45m4

                      @JonB said in " QDialog::Accepted" is doesn't work.:

                      Signals on different objects which happen to have the same name, like, accepted(). I really don't know how much clearer I can be. QDialogButtonBox::accepted() signal does NOT raise/emit QDialog::accepted() signal

                      @JonB ... whoops :o)
                      a

                      @MyNameIsQt Yes, the new version looks much better :)

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by JonB
                      #15

                      @Pl45m4 said in " QDialog::Accepted" is doesn't work.:

                      @JonB ... whoops :o)

                      Penny dropped :)
                      It's a bit fast, but is that a video of Burt Reynolds?? If so which movie?

                      Pl45m4P 1 Reply Last reply
                      1
                      • JonBJ JonB

                        @Pl45m4 said in " QDialog::Accepted" is doesn't work.:

                        @JonB ... whoops :o)

                        Penny dropped :)
                        It's a bit fast, but is that a video of Burt Reynolds?? If so which movie?

                        Pl45m4P Offline
                        Pl45m4P Offline
                        Pl45m4
                        wrote on last edited by Pl45m4
                        #16

                        @JonB

                        Yes, it's him. Must be "Nobody Is Perfect (The End)".


                        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                        ~E. W. Dijkstra

                        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