How Do I Append An Item To My Listmodel That's Been Defined Not In The Main.qml File
Let's say I have a ListModel component in A.qml: ListModel { id: alphabetModel } I have a seperate JS file to append items into my ListModel: alphabetModel.append({'Letter': '
Solution 1:
Look at Including a JavaScript Resource from Another JavaScript Resource
This following example is taken from the link above :
importQtQuick2.0import"script.js"asMyScriptItem {
width: 100; height: 100MouseArea {
anchors.fill: parent
onClicked: {
MyScript.showCalculations(10)
console.log("Call factorial() from QML:",
MyScript.factorial(10))
}
}
}
script.js
// script.jsQt.include("factorial.js")
functionshowCalculations(value) {
console.log("Call factorial() from script.js:"),factorial(value));
}
factorial.js
// factorial.jsfunctionfactorial(a) {
a = parseInt(a);
if (a <= 0)
return1;
elsereturn a * factorial(a - 1);
}
Post a Comment for "How Do I Append An Item To My Listmodel That's Been Defined Not In The Main.qml File"