Open new window



  • Hello,

    I have a simple (maybe stupid) question but I didn't find the information for QML controls2.

    I have a main window with a rectangle. When the user click on this rectangle, I want to open a second window on top of the main window (like a configuration window).

    My main file is:

    import QtQuick 2.7
    import QtQuick.Controls 2.0
    import QtQuick.Layouts 1.0
    
    ApplicationWindow {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        Rectangle
        {
            width: 100
            height: 100
            color:"#000000"
            MouseArea
            {
                anchors.fill:parent
                onClicked:open("newwin.qml")
            }
        }
    }
    

    The line "onClicked:open("newwin.qml")" should be replaced by the proper command.

    Thank you very much,

    Alex



  • Hello again,

    I found this:

                onClicked:
                {
                    var component = Qt.createComponent("\Newwin2.qml");
                    win = component.createObject();
                    win.show();
                }
    

    It works, but I am not sure it is the right way to do it. The component is created but I am not sure if it is destroyed.
    Could you help me out ?

    Thank you very much,

    Alex


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.