It is possible to do this in QML:
Item
{
property var refreshChart: function () {}
Component.onCompleted:
{
refreshChart = function ()
{
console.log("Hello!")
}
}
}
Also, an event handler can be connected dynamically:
Item
{
TapHandler {
id: inputHandler
}
Component.onCompleted: {
inputHandler.tapped.connect(MyScript.jsFunction)
}
}
or with anonymous function:
function openList()
{
var list = listSource.getMarkets(sortBy)
list.filterChanged.connect(function() { console.log("TableModel has been changed.") })
list.filter = filter
ml.model = list
}
Anonymous function with two parameters:
var order = market.createLimitOrder(buy, amount, price)
order.failed.connect(function(code, message) { fading.show("The order has filed: %1".arg(message))})
Rectangle {
id: colorbutton
width: 200; height: 80;
color: "red"
TapHandler {
id: inputHandler
}
Component.onCompleted: {
color = Qt.binding(function() { return inputHandler.pressed ? "steelblue" : "lightsteelblue" });
}
}