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. How to load multiple files from main.qml ?
Forum Update on Monday, May 27th 2025

How to load multiple files from main.qml ?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
multiple fileswindowsqml filesseparate files
4 Posts 3 Posters 1.7k 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.
  • N Offline
    N Offline
    Natalya
    wrote on 3 Jun 2018, 19:47 last edited by
    #1

    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 !

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 3 Jun 2018, 20:11 last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • N Offline
        N Offline
        Natalya
        wrote on 3 Jun 2018, 20:33 last edited by
        #3

        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 :

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

        Have a good day !

        P 1 Reply Last reply 4 Jun 2018, 17:51
        0
        • N Natalya
          3 Jun 2018, 20:33

          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 :

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

          Have a good day !

          P Offline
          P Offline
          Pablo J. Rogina
          wrote on 4 Jun 2018, 17:51 last edited by
          #4

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

          Upvote the answer(s) that helped you solve the issue
          Use "Topic Tools" button to mark your post as Solved
          Add screenshots via postimage.org
          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0

          4/4

          4 Jun 2018, 17:51

          • Login

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