-
Bug
-
Resolution: Unresolved
-
P1: Critical
-
5.12.5
Documentation states:
Beginning with Qt 5.11 ListElement also allows assigning a function declaration to a role. This allows the definition of ListElements with callable actions.
Trying to emit signal from ListView delegate:
signal signal1
signal signal2
signal signal3
ListView {
id: listView
model: myModel
delegate: Item {
Label {
id: text
text: model.name
}
MouseArea {
anchors.fill: parent
onClicked: {
model.func()
}
}
}
}
1st model variant with func:
ListModel {
id: myModel
ListElement {
name: qsTr("Item1")
func: signal1()
}
ListElement {
name: qsTr("Item2")
func: signal2()
}
ListElement {
name: qsTr("Item2")
func: signal3()
}
}
Produces error:
ListElement: cannot use script for property value
2nd variant with append:
ListModel {
id: myModel
Component.onCompleted: {
append({ name: qsTr("Item1"), func: function() { signal1() }})
append({ name: qsTr("Item2"), func: function() { signal2() }})
append({ name: qsTr("Item3"), func: function() { signal3() }})
}
}
Has other error:
TypeError: Property 'func' of object QQmlDMAbstractItemModelData(0x67a25f0) is not a function
Is it a bug or incorrect syntax? Documentation has no example.
P.S. Current workaround with list<QtObject> array: https://stackoverflow.com/a/50625374/630169
- relates to
-
QTBUG-140900 Crash when assigning a function declaration to a ListElement(for nested lists)
-
- In Progress
-