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

Please improve the ListModel in QML!

    XMLWordPrintable

Details

    • All

    Description

      1. The ListModel type in QML does not support property binding, as it cannot bind a property of a UI control to a property of a ListElement.
      2. The object returned by the get(index) method is a value copy, not a reference to a ListElement. It is not possible to modify the data of the source ListElement through this returned object, and can only be modified through setProperty(), which is very unreasonable!
      3. Another most serious issue is the existence of properties, as you did not provide a so-called hasOwnProperty() method or "===undefined" or "property in obj" like JavaScript to determine whether a certain property exists in the ListElement. For example, in the following case:

      ApplicationWindow {
          visible: true
          width: 640
          height: 480
      
          ListModel {
              id: globalModel
              ListElement { moduleId: "module1"; power: 30; wavelength: 650 }
              ListElement { moduleId: "module2"; power: 50; wavelength: 700 }
      
              ListElement { moduleId: "module3"; wavelength: 500 }
              ListElement { moduleId: "module4"; power: 80 }
              ListElement { moduleId: "module5"; power: 80 }
              ListElement { moduleId: "module6" }
              ListElement { }
          }
      
          ComboBox {
              id: comboBox
              model: globalModel
              currentIndex: 0
              textRole: "moduleId" 
              onCurrentIndexChanged: {
                  // No matter how I switch, the output is always false
                  console.log(globalModel.get(currentIndex).power === undefined, globalModel.get(currentIndex).wavelength === undefined)
                  
                  //When I switched to the last one, it output undefined 0 0, which means the last ListElement's moduleId field is undefined! But the power and wavelength attributes are 0, so logically they should also be undefined!         
                  var currentItem=globalModel.get(currentIndex)
                  console.log(currentItem.moduleId,currentItem.power,currentItem.wavelength)
              }
          }
      }
      

      Attachments

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

        Activity

          People

            qtqmlteam Qt Qml Team User
            xiangshu 马 象平
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes