Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

    Unsolved Adding ListModel data to a model

    QML and Qt Quick
    2
    2
    98
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • G
      gabor53 last edited by

      Hi,
      I am trying to add ListModel items to a model used to populate a SimpleSection and a repeater:

      import Felgo 3.0
      import QtQuick 2.9
      import QtQuick.Controls 2.5
      import QtQuick.Controls.Styles 1.4
      import QtQuick.LocalStorage 2.12
      import "Database.js" as JS

      App {

      AppListView {
          id: myListView
      
          ListModel {
              id: listModel
          }
      
          model: {
              var model = []
              for (var i = 0; i < 26; i++) {
                  for (var j = 0; j <= listModel.count; j++) {
                      var entry = {
                          "section": String.fromCharCode((65 + i)),
                          "items": [{
                                  "text": listModel.wordField
                              }]
                      }
                  }
                  model.push(entry)
              }
              return model
          }
      
          // add sections as regular list items
          delegate: Item {
              width: parent.width
              height: contentCol.height
      
              // each list-entry holds the section header + section items
              Column {
                  id: contentCol
                  width: parent.width
      
                  // header
                  SimpleSection {
                      // manually set otherwise induced section title
                      property string section: modelData.section
      
                      width: parent.width
                      enabled: true // clickable sections
                      onSelected: {
                          sectionItems.visible = !sectionItems.visible
                      }
                  }
      
                  // items
                  Column {
                      id: sectionItems
                      width: parent.width
                      visible: false
      
                      //show all items of section with repeater
                      Repeater {
                          model: modelData.items
                          delegate: SimpleRow {
                              text: modelData.text
                          }
                      }
                  }
              }
          }
      }
      

      }

      When I replace the "listModel.wordField" in the model for a string like "car" it works. I assume the problem is that I incorrectly assign string to "text" which causes the "Unable to assign [undefined] to QString" error message. Please help me to figure out the right way of doing this.
      Thank you for your help.

      1 Reply Last reply Reply Quote 0
      • P
        Padlock last edited by

        Have a look at these documents:
        https://doc.qt.io/qt-5/qml-string.html
        https://doc.qt.io/qt-5/qml-qtqml-string.html

        I believe you need a string, not a String.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post