Thanks njzk2, that works, but it makes the main2.qml file to be loaded from the beginning, and if the app is comprised of many different screens I guess that could lead to a performance degradation.
I managed to make it work loading additional files dinamically in the following way:
In the main file I have this:
Code:
...
...
Loader {
id: mainLoader
anchors.fill: parent
}
Rectangle {
id: firstItem
anchors.fill: parent
...
...
Connections {
target: mainLoader.item
onShowScreen: mainLoader.source = file;
}
...
MouseArea{
anchors.fill: parent
onClicked: {mainLoader.source = "main2.qml"; firstItem.opacity = 0;}
}
}
And in the other files that are going to be called, I have this:
Code:
signal showScreen(string file)
...
...
MouseArea {
...
...
onClicked: myRectangle.showScreen("otherFile.qml")
}
This way only the main file and one additional file is loaded in memory at any time, and it works well visually, but it gets complicated when the application needs to call many different screens and needs to be able to navigate to other previously opened ones.
On the other hand, using the opacity property to hide previous screens and to be able to get the new screens to react to user interaction seems more like a workaround to me, and make these questions arise:
Is this the correct way to switch screens in QML ?
Should QML be used for this kind of apps that need to be able to navigate between many different screens, or should I be using a QWidget based UI instead ?