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. Loading qml file several times without closing
Qt 6.11 is out! See what's new in the release blog

Loading qml file several times without closing

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 1.0k Views 1 Watching
  • 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.
  • R Offline
    R Offline
    RLocksley
    wrote on last edited by RLocksley
    #1

    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 ?

    ODБOïO 1 Reply Last reply
    0
    • R RLocksley

      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 ?

      ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      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 ?

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RLocksley
        wrote on last edited by RLocksley
        #3

        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]
                }
            }
        
        }
        
        
        ODБOïO 1 Reply Last reply
        0
        • R RLocksley

          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]
                  }
              }
          
          }
          
          
          ODБOïO Offline
          ODБOïO Offline
          ODБOï
          wrote on last edited by ODБOï
          #4

          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

          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