Please nominate your Qt Champions for 2021!

How to load multiple files from main.qml ?

  • Hi everyone,

    I'm trying to create my first app, using qml, and I'm facing a wall :

    I want to create 2 windows, both are done but as the code is quite long for each of them in one file + the connections, I wanted to separate them in two files. But I don't know how to load "win1.qml" and "win2.qml" at start from my "main.qml" file, loaded by my "main.cpp". How can I do that ? I could'nt find anything working on the web yet :(

    Thanks for your help !

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You should take a look at the RSS Feed QtQuick example. It uses several separated components within the same source tree.

    Hope it helps

  • Hi SGaist, thanks a lot.

    I have found a solution in the meantime : I am using this and it works just fine ! (It takes few seconds to appear but I don't really care).
    Nonetheless thanks a lot for your answer, I will take a closer look at it to find a better way to do what I want.

    Here's how I managed to do my file separation :

        running: true
        repeat: false
        onTriggered: {
            var componentA = Qt.createComponent("driverWindow.qml")
            if (componentA.status === Component.Ready)
            var componentB = Qt.createComponent("graphsWindow.qml")
            if (componentB.status === Component.Ready)

    Have a good day !

  • @Natalya if your issue is solved, please don't forget to mark your post as such. Thanks.