-
Suggestion
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
4.7.3
-
None
-
Symbian^3, Qt4.7.3.
Use the following code:
Dialog.qml
...
Rectangle {
...
function launch(options) {
log(options);
if (options.length === 0)
return;
...
optionslist.model = options;
}
Column {
...
Repeater {
id: optionslist
ARepeatedItem {
text: modelData.name
onDoSomething: {
modelData.action();
}
Component.onCompleted: {
log(modelData);
}
}
}
}
}
MyUI.qml
...
Dialog {
id: dialog
anchors.fill: parent
}
...
dialog.launch([{
name: qsTr("A"),
action: function() {
// DoStuff A
}},
{
name: qsTr("B"),
action: function() {
// DoStuff B
}}]);
When launch is executed, the expected result (depending on the implementation of "log" is:
array options: [
object 0:
string name: Walk
function action: function () {
// DoStuff A
}
object 1:
string name: Drive
function action: function () {
// DoStuff B
}
] (array options)
object modelData:
function action: function () {
// DoStuff A
}
string name: A
object modelData:
function action: function () {
// DoStuff B
}
string name: B
The actual result is:
array options: [
object 0:
string name: Walk
function action: function () {
// DoStuff A
}
object 1:
string name: Drive
function action: function () {
// DoStuff B
}
] (array options)
object modelData:
object action:
undefined arguments: undefined
undefined callee: undefined
undefined caller: undefined
number length: 0
string name:
string name: A
object modelData:
object action:
undefined arguments: undefined
undefined callee: undefined
undefined caller: undefined
number length: 0
string name:
string name: B
The conversion of the functions into objects prevents the onDoSomething handler from calling the passed function.
- relates to
-
QTBUG-69771 Functions in QML model data not accessible
-
- Open
-