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

Window.close() should not be callable in QML

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Duplicate
    • Affects Version/s: 5.3.2
    • Fix Version/s: None
    • Component/s: Quick: Other
    • Labels:
      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

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

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes