Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Adding ListModel data to a model
QtWS25 Last Chance

Adding ListModel data to a model

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 192 Views
  • 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 Offline
    G Offline
    gabor53
    wrote on last edited by
    #1

    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
    0
    • P Offline
      P Offline
      Padlock
      wrote on last edited by
      #2

      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
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved