Natatos
Natatos

Reputation: 145

How can I load a external QML file in Qt Quick?

Ok like if I'm trying to make something like a menu for a simple game. How can I make it so that when the start button is clicked it loads a different QML file?

Upvotes: 2

Views: 2941

Answers (1)

Dotti
Dotti

Reputation: 791

You can use Qt.createComponent() or Loader. For example:

import QtQuick 1.0

Item {
  MyButton {
    onClicked: loader.source = "MyGameFile.qml"
  }
  Loader {
    id: loader
    anchors.fill: parent
  }
}

Upvotes: 5

Related Questions