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. Accessing model roles in qml
Forum Updated to NodeBB v4.3 + New Features

Accessing model roles in qml

Scheduled Pinned Locked Moved QML and Qt Quick
1 Posts 1 Posters 569 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.
  • U Offline
    U Offline
    ustulation
    wrote on last edited by
    #1

    Hi,
    The usual way of accessing roles is using model.roleName
    @ListModel {
    id: mod
    ListElement { role0: "hello"; role1: "aaa" }
    ListElement { role0: "helloThere"; role1: "bbb" }
    }

    //.....
    Repeater {
    model: mod
    delegate: Text {//....
    text: model.role0
    }
    }@

    If i require that i have a line-edit where i can type in a role to be considered during the runtime then the above way of accessing the roles at runtime fails.
    But this seems to be equivalent
    @Text {//...
    text: model["role0"] //is this legal (it works btw) instead of model.role0 ?
    }@

    Now it's basically a string so i can dynamically input the role and the display would change according to the specified role. But this is not documented anywhere, just stumbled upon it. The question is if this (the second method) is a standard way to do it? Otherwise what is the way i can specify the role during the runtime ?

    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