Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-19219

Repeater model data does not support arrays of functions - functions are converted into

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 4.7.3
    • None
    • Symbian^3, Qt4.7.3.

    Description

      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.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              Unassigned Unassigned
              robert.williamson@nokia.com Rob Williamson
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes