Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Loading qml file several times without closing



  • I have a QML / Qt Application which loads a .qml file several times, with different models.

    But before loading the file the second time the Application closes the first.

    So my question is how do I load a qml file several times without closing anything ?



  • hi
    @RLocksley said in Loading qml file several times without closing:

    Qt Application which loads a .qml file several times

    How do you load the file exactly ?
    Are you using a the Loader type ? Can you show a minimal example to explain your issue ?



  • Thanks for your fast reply.

    Below is the frontend code of a minimal example of my problem.

    main.qml

    import QtQuick 2.12
    import QtQuick.Window 2.12
    import QtQuick.Controls 2.12
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("ConnectionList")
    
    
        ListView {
            anchors.fill: parent
            model: models["list"].length
    
            delegate: Text {
                id: chatPartner
                text: models["list"][index]
    
                MouseArea {
                    anchors.fill: parent
                    onClicked: { appCore.receiveChatPartner( chatPartner.text ) }
                }
            }
        }
    
    
    
        Connections {
            target: appCore
            onSendModel:{
                chatLoader.setSource( "qrc:/Chat.qml", { "a_model": _model } )
               
            }
        }
            Loader {
                        anchors.fill: parent
                        id: chatLoader
                    }
    
    }
    

    chat.qml

    import QtQuick 2.0
    import QtQuick.Window 2.0
    
    
    Window {
        visible: true
        id: chatwindow
        height: 300
        width: 300
        title: "ChatWindow"
        
        property string a_model
    
        ListView {
            anchors.fill: parent
            model: models[a_model].length
            delegate: Text {
                text: models[a_model][index]
            }
        }
    
    }
    
    


  • So you want to open Chat.qml (window) multiple times ?
    You can't do it with the loader, it loads only one Component at the time
    try to create your windows dynamically


Log in to reply