I'm testing a custom popup menu strategy when I came across some odd behaviour: Requests to delete my dynamically created popup window are ignored.
Window {
id: window
width: 400
height: 400
color: "red"
Rectangle {
id: base
width: 100
height: 100
anchors.centerIn: parent
color: "green"
property Window parentWindow: window
property Window popup: null
MouseArea {
anchors.fill: parent
onClicked: {
base.popup = popupComp.createObject( null, { "parentWindow": base.parentWindow } );
}
}
Connections {
target: base.parentWindow
onClosing: {
if ( base.popup !== null ) {
base.popup.hide();
base.popup.destroy(); // 2
}
}
}
Component {
id: popupComp
Window {
width: 150
height: 150
x: parentWindow.x + base.mapToItem( null, 0, 0 ).x
y: parentWindow.y + base.mapToItem( null, 0, base.height ).y
flags: Qt.Popup
color: "blue"
visible: true
property Window parentWindow: null
Component.onCompleted: requestActivate()
Component.onDestruction: {
console.log( "Destroying popup" );
}
onActiveChanged: {
if ( !active ) {
console.log( "Popup inactive" );
hide();
base.popup = null;
destroy(); // 1
}
}
}
}
}
}
I have to create the popup window dynamically because it's the only way to specify no parent, as a subwindow's (i.e. a parented window) QWindow::active state seems to be dependent upon it's parent's.
Once the popup window is closed the popup's destroy() slot is called via the onActiveChanged handler - but object is not destroyed until the parent window's closing() signal is emitted. Here is the debug output from opening and closing the popup twice:
qml: Popup inactive
qml: Popup inactive
// Closing the parent window now
qml: Destroying popup
qml: Destroying popup
Any idea why the destroy() call at 1 is ignored whilst granted at 2?