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. Expose ListModel role as property
Qt 6.11 is out! See what's new in the release blog

Expose ListModel role as property

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

    Hi everybody,

    currently I'm working on an TextInput component with a binding to a model. Therefore I wanted to expose the responsible role for the ListItem as an property so that I can reuse the component multiple times.

    Here the code snippets (only relevant stuff, model is named "myListModel")

    MyInput.qml:
    @import QtQuick 1.1

    Item {
    property variant modelRole: xval // also with string this doesn't work

     TextInput {
          text: myListModel.get(randomId...).modelRole
     }
    

    }
    @

    MAIN:
    @import QtQuick 1.1
    Rectangle {
    id: root

     MyInput {
          modelRole: xval
     }
    
     MyInput {
          modelRole: yval
     }
    
     MyInput {
          modelRole: anotherrole
     }
    

    }
    @

    with the string as property I get

    @Unable to assign [undefined] to QString text (in myTextInput.qml on the line of the text assignment)@

    and without the string (written like a variable see example above) I get additionally:

    @Reference Error: Can't find variable: xval (in myTextInput.qml on the line of definition of the property)@

    I found already something that worked with a model: http://comments.gmane.org/gmane.comp.lib.qt.qml/1778 but there is nothing about exposing a role.

    I think the main problem is the type of the property, but what is the appropiate property type for this case?

    Best regards
    Florian

    1 Reply Last reply
    1

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved