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

Native Cocoa dialogs: improper signal emission

    XMLWordPrintable

Details

    • macOS
    • 916a8c44c4a9ba639e89660226d14d51ed44feaa

    Description

      ColorDialog:

      • QColorDialog::colorSelected() emitted TWICE on accept
      • QML ColorDialog.color is updated before accept

      FontDialog:

      • QFontDialog::fontSelected() emitted TWICE on accept

      FileDialog:

      • QFileDialog::file(s)Selected() emitted TWICE on accept

      A test case with QtWidgets dialogs:

      #include <QtWidgets>
      
      //#define DONT_USE_NATIVE_DIALOGS
      
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
      
          QColorDialog colorDialog;
      #ifdef DONT_USE_NATIVE_DIALOGS
          colorDialog.setOption(QColorDialog::DontUseNativeDialog);
      #endif
          QObject::connect(&colorDialog, &QColorDialog::colorSelected, [](const QColor &c) { qDebug() << "QColorDialog::colorSelected" << c; });
          QObject::connect(&colorDialog, &QColorDialog::currentColorChanged, [](const QColor &c) { qDebug() << "QColorDialog::currentColorChanged" << c; });
          colorDialog.show();
      
          QFontDialog fontDialog;
      #ifdef DONT_USE_NATIVE_DIALOGS
          fontDialog.setOption(QFontDialog::DontUseNativeDialog);
      #endif
          QObject::connect(&fontDialog, &QFontDialog::fontSelected, [](const QFont &f) { qDebug() << "QFontDialog::fontSelected" << f; });
          QObject::connect(&fontDialog, &QFontDialog::currentFontChanged, [](const QFont &f) { qDebug() << "QFontDialog::currentFontChanged" << f; });
          fontDialog.show();
      
          QFileDialog fileDialog;
      #ifdef DONT_USE_NATIVE_DIALOGS
          fileDialog.setOption(QFileDialog::DontUseNativeDialog);
      #endif
          QObject::connect(&fileDialog, &QFileDialog::fileSelected, [](const QString &f) { qDebug() << "QFileDialog::fileSelected" << f; });
          QObject::connect(&fileDialog, &QFileDialog::currentChanged, [](const QString &f) { qDebug() << "QFileDialog::currentChanged" << f; });
          QObject::connect(&fileDialog, &QFileDialog::directoryEntered, [](const QString &f) { qDebug() << "QFileDialog::directoryEntered" << f; });
          fileDialog.show();
      
          return app.exec();
      }
      

      When DONT_USE_NATIVE_DIALOGS is defined, it uses QWidget based dialogs instead, and then the behavior is correct.

      A test case with QtQuick Dialogs:

      import QtQuick 2.5
      import QtQuick.Window 2.2
      import QtQuick.Dialogs 1.2
      
      Window {
          width: 640
          height: 480
          visible: false
      
          ColorDialog {
              visible: true
              onColorChanged: console.log("onColorChanged:", color)
              onCurrentColorChanged: console.log("onCurrentColorChanged:", currentColor)
          }
      
          FontDialog {
              visible: true
              onFontChanged: console.log("onFontChanged:", font)
              onCurrentFontChanged: console.log("onCurrentFontChanged:", currentFont)
          }
      
          FileDialog {
              visible: true
              onFileUrlChanged: console.log("onFileUrlChanged:", fileUrl)
              onFileUrlsChanged: console.log("onFileUrlsChanged:", fileUrls)
          }
      }
      

      QtQuick Dialogs don't suffer from the duplicate "selected" signals, because they are wired to a property.

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-55299
          # Subject Branch Project Status CR V

          Activity

            People

              Unassigned Unassigned
              jpnurmi J-P Nurmi
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes