Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Window and Dialog unexpected visible behavior
Forum Updated to NodeBB v4.3 + New Features

Window and Dialog unexpected visible behavior

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
visiblebehaviordialogwindowunexpected
2 Posts 1 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    eyvx
    wrote on last edited by p3c0
    #1

    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 Destroyed

    Once 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 changed

    I'll appreciate too much If somebody could help me with this strange case.
    Thanks in advance.

    Kind regards.

    1 Reply Last reply
    0
    • E Offline
      E Offline
      eyvx
      wrote on last edited by
      #2

      No ideas? =(

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved