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. QML List fetches DisplayRole from model; how can I change that?
Forum Updated to NodeBB v4.3 + New Features

QML List fetches DisplayRole from model; how can I change that?

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 3 Posters 2.8k 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.
  • M Offline
    M Offline
    Moschops
    wrote on last edited by
    #1

    I have some QML (that I did not write and to be honest do not understand, but nonetheless need to maintain) code that looks a lot like this:

    @
    Item {
    anchors {
    fill: parent
    margins: 30
    }

        List {
            id: recentList
            header: qsTr("Open Item")
            model: recentModel
            anchors {
                left: parent.left
                right: parent.right
                top: parent.top
            }@
    

    The recentModel is a proper QT model, and what gets displayed looks like the returned value from a call to data with the role parameter set to DisplayRole. I'd like it to fetch a different string, as if it was calling data with otherRole. I've been rooting around the QML documentation, but selecting with data role doesn't seem to come up. Is it possible?

    1 Reply Last reply
    0
    • E Offline
      E Offline
      eliseev
      wrote on last edited by
      #2

      You must explicitly create mapping of role names in QAbstractItemModel::roleNames() for QML to access data in the model. Then QML will know how to map accessed property to role when calling data().
      Is this sufficient help for you?

      "Doc is here":http://qt-project.org/doc/qt-5.0/qtquick/qtquick-modelviewsdata-cppmodels.html#qabstractitemmodel, but it looks like lacking sample code :/

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Moschops
        wrote on last edited by
        #3

        bq. Is this sufficient help for you?

        It may well be, thank you. I am using 4.8 to maintain a Solaris compatibility, but the function does exist in 4.8

        1 Reply Last reply
        0
        • S Offline
          S Offline
          stan.m
          wrote on last edited by
          #4

          bq. "Doc is here":http://qt-project.org/doc/qt-5.0/qtquick/qtquick-modelviewsdata-cppmodels.html#qabstractitemmodel [qt-project.org], but it looks like lacking sample code :/

          The sample code installs on your computer with Qt. On my drive it is:

          Qt/Qt5.2.1/5.2.1/Src/qtdeclarative/examples/quick/models/abstractitemmodel/

          The examples in the source code installed with Qt are incredibly useful. I wasted hours searching for sample code on the Internet that was already on my hard drive.

          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