Window and Dialog unexpected visible behavior
-
Hi all.
I'm developing an app that must control the children destruction. It should be comprehensive with the following example:
Child: Test.qml
import QtQuick 2.5 import QtQuick.Controls 2.0 import QtQuick.Window 2.2 Window { id: root visible: true width: 1600 height: 800 title: qsTr("Parent Window") Component.onDestruction: { console.log("Parent Destroyed") } Rectangle { anchors.fill: parent Button { id: createButton text: "Create" onClicked: { createNewWindow(); } } } function createNewWindow() { for(var i=0; i<1; i++){ var component = Qt.createComponent("qrc:/Test.qml"); if (component.status === Component.Ready) { var dialog = component.createObject(root); dialog.visibleChanged.connect( function() { console.log("Signal executed"); if (!dialog.visible) dialog.destroy() } ); } } } }
Parent: main.qml
import QtQuick 2.5 import QtQuick.Controls 2.0 import QtQuick.Window 2.2 Window { id: root visible: true width: 1600 height: 800 title: qsTr("Parent Window") Component.onDestruction: { console.log("Parent Destroyed") } Rectangle { anchors.fill: parent Button { id: createButton text: "Create" onClicked: { createNewWindow(); } } } function createNewWindow() { for(var i=0; i<1; i++){ var component = Qt.createComponent("qrc:/Test.qml"); if (component.status === Component.Ready) { var dialog = component.createObject(root); dialog.visibleChanged.connect( function() { console.log("Signal executed"); if (!dialog.visible) dialog.destroy() } ); } } } }
As you can check, if I close the child window, the property visible will change to false, emitting the visibleChanged() signal, catched and handled in the parent one to destroy the instance. The log is like this:
qml: Component created.
qml: Visible changed
qml: Signal executed
qml: Component destroyed.
qml: Parent DestroyedOnce this case has been understood, the issue stay in: why if I have a Dialog instead of Window child, this signal does not exist? (Just change the reserved word "Window" in test.qml by "Dialog". The log written by QML is the following one when I close the child window:
qml: Component created.
qrc:/main.qml:34: Error: Function.prototype.connect: this object is not a signal
qml: Visible changedI'll appreciate too much If somebody could help me with this strange case.
Thanks in advance.Kind regards.