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

Make the result property of QQuickAbstractDialog consistent with QDialog, or vice versa.

    XMLWordPrintable

Details

    • All
    • b00798df9 (dev), 18fc3862d (6.6), ec8564963 (tqtc/lts-6.5), 8dd687836 (dev)

    Description

      The QDialog::result() and QDialog::setResult() functions reflects either the last standard button that was clicked by the user or the index of the last custom button that was clicked.

      It has nothing to do with whether the dialog was accepted, or rejected.

      This is the implementation:

      // qdialog.cpp
      void QDialog::done(int r)
      {
          QPointer<QDialog> guard(this);
          Q_D(QDialog);
          d->close(r);
          if (!guard)
              return;
          int dialogCode = d->dialogCode();
          if (dialogCode == QDialog::Accepted)
              emit accepted();
          else if (dialogCode == QDialog::Rejected)
              emit rejected();
          if (guard)
              emit finished(r);
      }
      // qmessagebox.cpp
      int QMessageBoxPrivate::dialogCode() const
      {
          Q_Q(const QMessageBox);
          if (clickedButton) {
              switch (q->buttonRole(clickedButton)) {
              case QMessageBox::AcceptRole:
              case QMessageBox::YesRole:
                  return QDialog::Accepted;
              case QMessageBox::RejectRole:
              case QMessageBox::NoRole:
                  return QDialog::Rejected;
              default:
                  ;
              }
          }
          return QDialogPrivate::dialogCode(); // returns result()
      }

      Instead of using the result to check for whether the dialog was accepted or rejected, it instead stores a reference to the last clicked button, and checks the role of that button.

      This differs from qt quick dialogs, where the result is an enum, which can either be Accepted, or Rejected.

       

      It would probably be a good idea to make these two API's behave similarly.

      I've attached a project that can be used to test the widgets based messagebox.

      The manual test at qtdeclarative/tests/manual/quickdialogs/dialogs can be used to test the qml based dialogs.

      Attachments

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

        Activity

          People

            hurlevent Oliver Eftevaag
            hurlevent Oliver Eftevaag
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: