QML Nested Repeater



  • I am trying to output a bunch of text from a nested collection.

    Assuming a collection myCollection with value:
    [[name:"Foo Barmaster", accesshistory: [ [day: "Monday", times:[ "5pm","6pm","9pm" ]],[day: "Tuesday", times:[ "1pm","3pm"]] ]],... ]

    Notice the nested collections. I intend to use this QML to output everything in the collection

    @
    Column{
    Repeater {
    model: myCollection

                    Text {
                        text: modelData.name
                        font.family: "Arial"
                        font.pixelSize: 13 
    
                    }
    
    
                    Repeater{
                        model: modelData.accesshistory
                        Text {
                            text: modelData.day
                            font.family: "Arial"
                            font.pixelSize: 13 * root.wfact
    
                        }
                        Text {
                            text: modelData.times.join()
                            font.family: "Arial"
                            font.pixelSize: 12 * root.wfact
                        }
                    }
    
    
    
            }
    

    }
    @

    However on the 2nd layer repeater, my program just blanks. It doesn't even give me an error.
    1st level repeater works on its own well if I comment out second layer of repeater. What gives?

    Are nested repeaters supported?



  • weird I think that should work, I have a nested repeater in my project that works just fine, also a ListView inside a Repeater and that works too!
    did you test it with a new project and simple nested model? I don't know how large the rest of you app is, might be a problem somewhere else? :)

    Edit: i think I see the problem, your model is wrong, you have used an array [day: ..] and not an object {day:..}
    in JavaScript you should use arrays for arrays with int index only and for dictionaries objects: { }
    like in QML if you use Item {} and not Item [] .. :D

    try your model with this syntax:
    @
    [{name:“Foo Barmaster”, accesshistory: [ {day: “Monday”, times:[ “5pm”,“6pm”,“9pm” ]},{day: “Tuesday”, times:[ “1pm”,“3pm”]} ]},… ]
    @



  • Ah! It seems only ONE item can be in a Repeater. So having multiple text items meant I had to wrap that in one item e.g (row, column, rectangle, item, etc)
    Following corrections in bold made things work:
    @
    Column{
    Repeater {
    model: myCollection
    delegate: Column{

                    Text {
                        text: modelData.name
                        font.family: "Arial"
                        font.pixelSize: 13
    
                    }
    
    
                    Repeater{
                        model: modelData.accesshistory
                        delegate: Column{
                        Text {
                            text: modelData.day
                            font.family: "Arial"
                            font.pixelSize: 13 * root.wfact
    
                        }
                        Text {
                            text: modelData.times.join()
                            font.family: "Arial"
                            font.pixelSize: 12 * root.wfact
                        }
                    }
                  }
              }
    
    
            }
    

    }@



  • oh yes that too, but QML should show an error if you try to add multiple items as a delegate!?



  • I didn't get an error in any of the logs.

    Essentially, the page (i.e component pushed into a stackview) that contained this code just silently didn't load.



  • just tried it in my program, when I try to run with more than 1 item as the delegate of a repeater I get an error "Cannot assign multiple values to a singular property" and "The program has unexpectedly finished."

    anyway did you change your model or is it working like that now? I always use the object notation for objects, like the JSON notation also that better to read I think.

    also tested it to be clear:
    @[foo:"bar"]@
    that is a syntax error, even qt creator can't parse that, so how is your code even running.. very weird with your model :p

    so you have to use
    @{foo:"bar"}@
    for objects (dictionaries)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.