title: How to access dynamically/randomly loaded Repeater items in QML?
body: <p>The answer provided by @TheBootroo here: <a href="https://stackoverflow.com/questions/13049896/qml-navigation-between-qml-pages-from-design-perception">link</a></p>
  
  <p>provides a way to load and change between QML files/screens/views. But when doing it like this how can one use signal and slots? </p>
  
  <p>One can access the items created by the repeater by using the Repeater::itemAt(index) method, but since I don't know in what order the items are loaded I don't know what index screen2, screen3, screen4 etc. is at.</p>
  
  <p>Is there any way to solve this or do one have to instantiate all the screens in memory at start up?</p>
  
  <p>My code below:</p>
  
  <p>main.qml:</p>
  
  <pre><code>//List of screens
      property variant screenList: [
          "main",
          "screen2",
          "screen3",
          ...
      ]
  
      //Set this to change screen
      property string currentScreen: "main"
  
  
      Repeater {
          id: screens
          model: screenList
          delegate: Loader {
              active: false;
              asynchronous: true
              anchors.fill:  parent
              source: "%1.qml".arg(modelData)
              visible: (currentScreen === modelData)
              onVisibleChanged: {
                  loadIfNotLoaded()
              }
              Component.onCompleted: {
                  loadIfNotLoaded()
              }
  
              function loadIfNotLoaded () {
                  //To load start screen
                  if(visible &amp;&amp; !active) {
                      active = true;
                  }
              }
          }
      }
  
      Connections {
          target: screens.itemAt(indexHere)
          //screen is here the string passed with the signal from screen2.
          onChangeScreen: currentScreen = screen
      }
  
      Button {
          id: button1
          text: "Go To Screen 2"
          onClicked: {
              currentScreen = "screen2"
          }
      }
  </code></pre>
  
  <p>And in screen2.qml:</p>
  
  <pre><code>signal changeScreen(string screen)
  
  Button {
      text: "Go To Main"
      onClicked: {
          changeScreen("main")
      }
  }
  </code></pre>