Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML Nested Repeater
Qt 6.12 LTS is out! See what's new in the release blog

QML Nested Repeater

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 2 Posters 6.4k Views 1 Watching
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      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”]} ]},… ]
      @

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        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
                            }
                        }
                      }
                  }
        
        
                }
        

        }@

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              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)

              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
              • Unsolved