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. What are the differences between accept and setResult

What are the differences between accept and setResult

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 2 Posters 910 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.
  • Q Offline
    Q Offline
    Qingshui Kong
    wrote on last edited by
    #1

    Hello everyone,
    Could somebody give me some advice?

    I create a sub dialog. I want to set the result to Accepted when I click some button. So I use code "setResult(Accepted)" in the slot function. But it doesn't work. The result is still Rejected. But if I use code "accept()" in the slot function, it works.

    So I wonder what are the differences between accept() and setResult(Accepted)?

    Thanks in advance.

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      accept() sets the result code to Accepted and closes the dialog, setResult() only sets the result code. If your result code is not what you expect you maybe overwrite it somewhere in between.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      Q 1 Reply Last reply
      3
      • Christian EhrlicherC Christian Ehrlicher

        accept() sets the result code to Accepted and closes the dialog, setResult() only sets the result code. If your result code is not what you expect you maybe overwrite it somewhere in between.

        Q Offline
        Q Offline
        Qingshui Kong
        wrote on last edited by
        #3

        @Christian-Ehrlicher
        Thank you very much.
        I see. I add close() after accept() and setResult(Accepted).
        But the result code is not what I set by using setResult(Accepted). Do you mean I should overwrite setResult() or some other functions?
        Thank you again.

        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Qingshui-Kong said in What are the differences between accept and setResult:

          I add close() after accept() and setResult(Accepted).

          Please show us some code - there is no need to call close() after accept(), only needed when you want to close the window when you only call setResult().
          Do you show a modal dialog? If so how to you exit the dialog when calling setResult()?

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          Q 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            @Qingshui-Kong said in What are the differences between accept and setResult:

            I add close() after accept() and setResult(Accepted).

            Please show us some code - there is no need to call close() after accept(), only needed when you want to close the window when you only call setResult().
            Do you show a modal dialog? If so how to you exit the dialog when calling setResult()?

            Q Offline
            Q Offline
            Qingshui Kong
            wrote on last edited by Qingshui Kong
            #5

            @Christian-Ehrlicher
            Yes, it should be a modal dialog.
            Here are some codes.
            At the begining, I use setResult.
            void VXFaultDialog::onBtnCloseClicked()
            {
            setResult(Accepted);
            close();
            }
            But it doesn't work. So I choose accept();
            void VXFaultDialog::onBtnCloseClicked()
            {
            accept();
            close();
            }
            Then it works.

            1 Reply Last reply
            0
            • Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Now I understand what you want. This is due to the fact that QDialog::closeEvent() sets the result code depending on the visibility of the dialog since this event can also be triggered from the outside. I would recommend to use accept()/reject()/done() as this is the recommended way stated in the documentation.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              Q 2 Replies Last reply
              3
              • Christian EhrlicherC Christian Ehrlicher

                Now I understand what you want. This is due to the fact that QDialog::closeEvent() sets the result code depending on the visibility of the dialog since this event can also be triggered from the outside. I would recommend to use accept()/reject()/done() as this is the recommended way stated in the documentation.

                Q Offline
                Q Offline
                Qingshui Kong
                wrote on last edited by
                #7

                @Christian-Ehrlicher
                OK. Thank you very much.

                1 Reply Last reply
                0
                • Christian EhrlicherC Christian Ehrlicher

                  Now I understand what you want. This is due to the fact that QDialog::closeEvent() sets the result code depending on the visibility of the dialog since this event can also be triggered from the outside. I would recommend to use accept()/reject()/done() as this is the recommended way stated in the documentation.

                  Q Offline
                  Q Offline
                  Qingshui Kong
                  wrote on last edited by
                  #8

                  @Christian-Ehrlicher
                  I use accept() or reject(). But the dialog doesn't close automatically. I have to use close() to close it.

                  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