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 reload the ListModel after updating the values of roles

How to reload the ListModel after updating the values of roles

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

    Hello,
    It's been 3 days and I haven't found a solution to my problem. Most of you probably know the reload() function in QML XmlListModel Element, which simply reloads the model. It's quite straightforward in XmlListModel, however, I cannot manage it with ListModel.
    I have a ListModel and the values of the roles are updated during runtime. I'd like to reload my model every time the values are updated.
    I've implemented my ListModels both in C++ and QML, even so I couldn't find a way to reload my model after modifying the values.
    Here are the example snippets,

    modelElement.qml
    @
    import Qt 4.7
    QtObject {
    property string source
    property string txt
    property string newTag;
    }
    @

    SampleModel.qml

    @
    Item{
    property list<QtObject> paramModel: [
    ModelElement {url : myfunction(input)},
    ModelElement {url: myfunction(input)},
    ModelElement {url: myfunction(input)},
    ModelElement {url: myfunction(input) }
    ]
    }
    @
    DummyDelegate.qml
    @
    Rectangle {
    id: myRect; width: 77; height: 77; color: "#dddddd"; smooth: true
    Image { id: thumb; source: url ; x: 1; y: 1; smooth: true; anchors.fill:parent }
    }
    states: [
    State {
    name: "moved" ;
    ParentChange { target: myRect; parent:middle; x:0;y:0}
    }
    ]
    @

    main.qml

    @

    import Qt 4.7
    Rectangle {
    id:mainWindow
    width:500
    height:500

    SampleModel{id:mymodel}

    Rectangle{
    id:rect
    width:200
    height:200
    color:"transparent"

    PathView {
        id: myPathView; model: myModel.paramodel pathItemCount:4
        delegate:DummyDelegate{}
         anchors.fill: parent
         path: Path {
             startX: 120; startY: 100
                    }
    }
    

    }@

    As you can see above, when the state is switched to "moved", the parent of the rectangle is changed so the number of the items in PathView is decreased. Here is what I want, I want to reload the models with updated values of url, so that image can change accordingly.

    Hope someone can help at this point.
    Thanks

    1 Reply Last reply
    0
    • A Offline
      A Offline
      apap_
      wrote on last edited by
      #2

      Did you try this in SampleModel.qml :
      @
      import QtQuick 1.0

      ListModel {
      ModelElement {url: myfunction(input) },
      ModelElement {url: myfunction(input) },
      ModelElement {url: myfunction(input) },
      ModelElement {url: myfunction(input) }
      }
      @

      But I think you should not store a function in the modelelements, just store values and when needed update the value in the model.

      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