Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.11.0
-
None
Description
When populating the model of a Repeater with Javascript objects and later accessing properties from those objects, all properties seem to be available except for functions (or possibly all non-POD types). These will be undefined when trying to access them through the model.
See following code for illustration:
import QtQuick 2.9 import QtQuick.Window 2.2 Window { visible: true width: 640 height: 480 title: qsTr("Hello World") Column { anchors.centerIn: parent Repeater { id: menu model: [ { label: "menu item #1", payload: 123, trigger: function() { console.debug("menu item 1 triggered") } }, { label: "menu item #2", payload: 345, trigger: function() { console.debug("menu item 2 triggered") } } ] delegate: Text { text: modelData.label MouseArea { anchors.fill: parent onClicked: { console.debug("Clicked " + modelData.label + " with payload " + modelData.payload + " and trigger function: " + modelData.trigger) modelData.trigger() } } } } } }
Notice when clicking the menu items that the label and payload are accessible, but that the trigger function is considered undefined.
Attachments
Issue Links
- relates to
-
QTBUG-43281 Functions within JS object are lost when used in models
- Reported
-
QTBUG-44541 QML model cannot store JS function
- Reported
-
QTBUG-84107 Using object list (array) as a model unable to track changes
- Closed
-
QTBUG-19219 Repeater model data does not support arrays of functions - functions are converted into
- Open