I try to save a variable from another QML object on root QML file using Settings. I can access the variable with myloader.item.number
but when I try it on Settings it gives error: Invalid alias target location: number
Is there a way to save the variable using Settings module?
MyPage.qml
import QtQuick 2.0
import QtQuick.Controls 2.12
Rectangle {
property alias number: combo.currentIndex
color: "red"
ComboBox{
id: combo
model: ["a","b","c"]
}
}
main.qml
import QtQuick 2.3
import QtQuick.Window 2.10
import Qt.labs.settings 1.1
Window{
visible: true
width: 200
height: 200
Component.onCompleted: {
console.log("loader property is:", myloader.item.number)
}
//
Loader{
id:myloader
//asynchronous: true
active: true
source: "MyPage.qml"
anchors.fill: parent
}
/*
// This can save the number with "property alias myNumber: mapage.number"
MyPage{
id: mapage
}
*/
Settings{
id: settings
// This gives error when using loader: Invalid alias target location: number
property alias myNumber: myloader.item.number
}
}
property int myNumber: myloader.item.number
– JarManSettings
object before. I just looked it up and now I understand how it works. You just need a different property to point the alias at. For instance, inside theLoader
, add an int property, and then point the alias at that. You'll probably need to initialize the combobox to read from that int too. I'll try it out when I get a chance. – JarMan