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

Wrong signal order when closing Dialog on macOS

    XMLWordPrintable

Details

    • macOS

    Description

      Steps to reproduce

      1. Run the code below
      2. Click "Open Dialog"
      3. Click on the TextEdit and enter "abc"
      4. Click "OK" (Important: do this while the TextEdit still has keyboard focus)

       

      import QtQuick
      import QtQuick.Controls
      import QtQuick.Layouts
      import QtQuick.Window
      import QtQuick.Controls.Material
      
      Window {
          width: 640
          height: 480
          visible: true
          id: root
      
          property string testString: ""
      
          Button {
              text: "Open Dialog"
              anchors.centerIn: parent
              onClicked: dialogLoader.active = true
          }
          
          Loader {
              id: dialogLoader
              active: false
              sourceComponent: dialogComponent
          }
      
          Component {
              id: dialogComponent 
              Dialog {
                  id: dialog
                  modal: true
                  parent: Overlay.overlay
                  anchors.centerIn: parent
                  width: parent.width * 0.5
                  height: parent.height * 0.5
                  RowLayout {
                      anchors.fill: parent
                      Label {
                          text: "Test:"
                      }
                      TextField {
                          id: textField
                          Layout.fillWidth: true
                          onEditingFinished: {
                              console.log("textField onEditingFinished")
                              root.testString = text
                          }
                      }
                  }
                  standardButtons: Dialog.Ok | Dialog.Cancel
      
                  onAccepted: {
                      console.log("dialog onAccepted")
      
                      //testString is not set yet
                      console.log(root.testString)
      
                      //even when calling Qt.callLater() it isn't set yet
                      Qt.callLater( () => { console.log(root.testString) } )
                  }
                  onClosed: Qt.callLater( () => { dialogLoader.active = false } )
      
                  Component.onCompleted: {
                      dialog.open()
      /*
                      // WORKAROUND:
                      let applyButton = standardButton( Dialog.Ok )
                      if( applyButton !== null )
                          applyButton.focusPolicy = Qt.StrongFocus
      */
                  }
              }
          }
      }
      

       

      Expected output (on Windows and Linux)

      qml: textField onEditingFinished
      qml: dialog onAccepted
      qml: abc
      qml: abc
      

       

      Actual output on macOS, Qt 6.2.7

      qml: dialog onAccepted
      qml: 
      qml: 
      qml: textField onEditingFinished
      

       

      Actual output on macOS, Qt 6.4.1

      qml: dialog onAccepted
      qml: 
      qml: textField onEditingFinished
      qml: abc
      

       

      Workaround

      Set focusPolicy = Qt.StrongFocus on the OK button

       

      Notes

      We should test Qt 5.15.12 too

      Attachments

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

        Activity

          People

            mikolaj.boc Mikołaj Boc (Inactive)
            skoh-qt Sze Howe Koh
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There is 1 open Gerrit change