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. How to read Array values and display in ListView?
Forum Updated to NodeBB v4.3 + New Features

How to read Array values and display in ListView?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 588 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.
  • L Offline
    L Offline
    lakshmanGiri
    wrote on last edited by
    #1

    Hi, I wanted to get and display the array values in the LIstView. The file is a js file.
    I have a file like this.

    data = [ 
    {
    name: 'parent 1'
    child: [{ name: 'child 1'} ,{ imageSource: 'child 2'}]
    },
    {
    name: 'parent 2'
    child: [{ name: 'child 1'} ,{ imageSource: 'child 2'}]
    }]
    

    I wanted to call this js file through model property and then wanted to display it using the delegate property.

    Can any one help me?. Thanks in advance

    raven-worxR 1 Reply Last reply
    0
    • L lakshmanGiri

      Hi, I wanted to get and display the array values in the LIstView. The file is a js file.
      I have a file like this.

      data = [ 
      {
      name: 'parent 1'
      child: [{ name: 'child 1'} ,{ imageSource: 'child 2'}]
      },
      {
      name: 'parent 2'
      child: [{ name: 'child 1'} ,{ imageSource: 'child 2'}]
      }]
      

      I wanted to call this js file through model property and then wanted to display it using the delegate property.

      Can any one help me?. Thanks in advance

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @lakshmanGiri

      ListView {
         property var modelData: [ 
            {
               name: 'parent 1'
               child: [{ name: 'child 1'} ,{ imageSource: 'child 2'}]
            },
            {
               name: 'parent 2'
               child: [{ name: 'child 1'} ,{ imageSource: 'child 2'}]
            }
         ]
      
         model: modelData.length
      
         delegate: Item {
             // access data with "modelData[index]"
         }
      }
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      L 1 Reply Last reply
      1
      • raven-worxR raven-worx

        @lakshmanGiri

        ListView {
           property var modelData: [ 
              {
                 name: 'parent 1'
                 child: [{ name: 'child 1'} ,{ imageSource: 'child 2'}]
              },
              {
                 name: 'parent 2'
                 child: [{ name: 'child 1'} ,{ imageSource: 'child 2'}]
              }
           ]
        
           model: modelData.length
        
           delegate: Item {
               // access data with "modelData[index]"
           }
        }
        
        L Offline
        L Offline
        lakshmanGiri
        wrote on last edited by
        #3

        @raven-worx Hi, Thanks for your reply. I tried the method you mentioned, but I couldn't display the data using the delegate property. I tried getting the value by modelData[index] in Text definition within the Item definition. The data was not displayed in the window.

        Am I missing anything?.

        raven-worxR 1 Reply Last reply
        0
        • L lakshmanGiri

          @raven-worx Hi, Thanks for your reply. I tried the method you mentioned, but I couldn't display the data using the delegate property. I tried getting the value by modelData[index] in Text definition within the Item definition. The data was not displayed in the window.

          Am I missing anything?.

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #4

          @lakshmanGiri
          if it's a property of the listview (as in my example) you can try to access the data with:

          ListView.view.modelData[index]

          from within the delegate instead.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          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