Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-86782

Add an exec() method to Dialog

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 5.15.1
    • Quick: Controls 2
    • None
    • All

    Description

      Consider two QML components named A and B, and a custom MessageDialog component that consist in a Dialog with a required message property. There is not an obvious way to reuse MessageDialog while keeping all three classes unaware of each other.

      The two obvious options are:

      1. Instantiate a MessageDialog for every message you want to handle
        With this the handling of messages is fully encapsulated, but there is an overload for the QML engine. Also, the amount of code will be significantly increased, making it more difficult to maintain.
      2. Instantiate MessageDialog only once, and handle all possible situations in the MessageDialog itself, or in its single instance. The amount of code is not increased and the QML engine is not overloaded, but there will not be any encapsulation: the MessageDialog will not only be aware of the existence of A and B, but it will also manage operations and access/modify properties.

      There are other options, like creating the MessageDialog dynamically, but I cannot think in one that makes the implementation small, intuitive, and not make the code difficult to understand.

      The purpose is adding a exec() function to Dialog in Qt Quick Controls 2 module that behaves like the one provided by the QDialog widget: blocks the application until the user closes the dialog by declining, and return the result code.

      Some years ago, when I was using widgets...

      bool MyWidget::processData(const QByteArray &data)
      {
          // ...
          if (result.empty()) {
              messageDialog.setMessage("Found nothing, try the hard method?");
              if (messageDialog.exec() == QDialog::Accepted) {
                  // ...
              }
          }
          // ...
      }
      

      Now, imagine this in Qt Quick Controls 2:

      onClicked() {
          messageDialog.message = "Remove all elements?"
          if (messageDialog.exec() === Dialog.Accepted) {
              model.clear()
          }
      }
      

      See? It's so beautiful... simple... short... concise... elegant... intuitive...

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              ceperez1996 Carlos Pérez
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes