Comment 2 for bug 1622717

Revision history for this message
Olivier Tilloy (osomon) wrote :

Here is the actual QML code contained in the example click package:

import QtQuick 2.4
import QtQuick.Window 2.2
QtObject {
  readonly property var allWindows: []
  property var windowFactory: Component {
    Window {
      onClosing: destroy()
      Component.onCompleted: allWindows.push(this)
      Component.onDestruction: {
        for (var w in allWindows) {
          if (this === allWindows[w]) {
            allWindows.splice(w, 1)
            return
          }
        }
      }
      Rectangle {
        anchors {
          fill: parent
          margins: 20
        }
        color: Qt.rgba(Math.random(), Math.random(), Math.random(), 1)
      }
      MouseArea {
        anchors.fill: parent
        onClicked: windowFactory.createObject(null).show()
      }
    }
  }
  property var applicationMonitor: Connections {
    target: Qt.application
    onAboutToQuit: console.log("quitting application, %1 windows open".arg(allWindows.length))
  }
  Component.onCompleted: windowFactory.createObject(null).show()
}