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 access ListModel element members in ListView's delegate via Loader
Forum Updated to NodeBB v4.3 + New Features

How to access ListModel element members in ListView's delegate via Loader

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 186 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.
  • R Offline
    R Offline
    RobertB
    wrote on last edited by RobertB
    #1
    ListModel {
        id: coolModel
        ListElement {
            name: "Bill Smith"
        }
        ListElement {
            name: "John Brown"
        }
    }
    
    Component {
        id: testTest
        Text {
            text: name
        }
    }
    
    ListView {
        anchors.fill: parent
        boundsBehavior: Flickable.StopAtBounds
        clip: true
        model: coolModel
    
        delegate: Loader {
            height: childrenRect.height
            width: parent.width
            sourceComponent: testTest
        }
    }
    

    How to access name in Component testTest ? Looks like the ListView's context (the variables from my ListModel) is not passed through the Loader.

    ReferenceError: name is not defined

    1 Reply Last reply
    0
    • F Offline
      F Offline
      felsi
      wrote on last edited by
      #2

      Try:

      ListView {
          anchors.fill: parent
          boundsBehavior: Flickable.StopAtBounds
          clip: true
          model: coolModel
      
          delegate: Loader {
              sourceComponent: Text{
                  text: model.name
              }
          }
      }
      

      or maybe you want in testTest:

      Item {
          property alias text: some_text.text
          Text {
              id: some_text
              text: "a name"
          }
      }
      
      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