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

Window.close() should not be callable in QML

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P2: Important
    • None
    • 5.3.2
    • Quick: Other
    • None

    Description

      Window.close() is not documented for QtQuick but for some reason it

      • pops up as a suggestion in Qt Creator
      • it exists as a valid function that closes a window

      The problem is, it does not emit closing() and thus you can not react to X-clicks and close() calls with one onClosing slot.

      The next problem is, you cannot re-implement the function. Assume you do the following to fix the problem above:

      function close() {
          var closeEvent = { accepted: true };
          childWindow.closing(closeEvent)
          if (closeEvent.accepted)
          {
              visible = false
          }
          else
          {
              console.log("Closing denied")
          }
      }
      

      and have the following slot

      onClosing: {
          console.log("Child window is closing …")
          close.accepted = false
      }
      

      Now, you have a name collision, since the slot parameter close is overwritten by the function name close.

      To avoid all this confusion, I think it is necessary to one of the following:

      • remove the Window.close() function from QML,
      • rename the parameter of the onClosing slot and let Window.close() emit closing

      Full example code available here: https://gist.github.com/webmaster128/c0724440033ef153bb96

      Attachments

        Issue Links

          Activity

            People

              aalpert Alan Alpert
              webmaster128 Simon Warta
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: