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 :
import QtQuick 2.0
import "script.js" as MyScript
Item {
width: 100; height: 100
MouseArea {
anchors.fill: parent
onClicked: {
MyScript.showCalculations(10)
console.log("Call factorial() from QML:",
MyScript.factorial(10))
}
}
}
script.js
// script.js
Qt.include("factorial.js")
function showCalculations(value) {
console.log("Call factorial() from script.js:"),factorial(value));
}
factorial.js
// factorial.js
function factorial(a) {
a = parseInt(a);
if (a <= 0)
return 1;
else
return 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"