Skip to content
  • 0 Votes
    2 Posts
    473 Views
    dheerendraD

    Any sample code to check on this ?

  • 0 Votes
    2 Posts
    898 Views
    DiracsbracketD

    Hi @larkei15
    I don't think using a Repeater for dynamically changing models is the best approach.

    From the Cadaques book:
    https://qmlbook.github.io/ch06/index.html

    For static models, a Repeater can be used as the view. It is easy to combine it with a positioner such as Row, Column, Grid or Flow to build user interface parts. For dynamic or large data models, a view such as ListView or GridView are more appropriate. These create delegate instances on the fly as they are needed, reducing the number of elements live in the scene at once.

    And from the QML doc:
    http://doc.qt.io/qt-5/qml-qtquick-repeater.html

    Considerations when using Repeater
    The Repeater type creates all of its delegate items when the repeater is first created. This can be inefficient if there are a large number of delegate items and not all of the items are required to be visible at the same time. If this is the case, consider using other view types like ListView (which only creates delegate items when they are scrolled into view) or use the Dynamic Object Creation methods to create items as they are required.

    I wager your syncing problems are due to that...

    Is there any reason why you are choosing the Column + Repeater approach over the ListView approach?

  • 0 Votes
    1 Posts
    720 Views
    No one has replied
  • what can do in workerscript?

    Unsolved QML and Qt Quick
    1
    0 Votes
    1 Posts
    435 Views
    No one has replied
  • 1 Votes
    10 Posts
    14k Views
    M

    @Hamed.Masafi I see your point. However, the attempt below still fails.
    The text in the Text element is shown correctly so there the title2() evaluates correctly (it also displays correctly when using a literal and/or when using no binding)
    However, as the example below illustrates, when using the same objects through a model in ListView.delegate, I still get the same errors as reported initially.

    Your second proposal indeed works (and is similar to the proposal of dheerendra above). However, this implies that the function gets evaluated for every item in the model while I would like to only evaluate the function for every visible item (=> when used in the delegate)

    import QtQuick 2.3 import QtQuick.Window 2.2 Window { visible: true width: 600 height: 360 property var someObject : makeSomeObject("SomeTitle1") function makeSomeObject(title){ var obj = { title: title, title2: Qt.binding (function() {return someObject.title}) }; return obj; } Text{ anchors.fill: parent text: someObject.title2() } ListView { anchors.fill: parent model: ListModel {id: list_model} delegate: Text {text: list_model.get(index).title2()} } Component.onCompleted: { list_model.append(makeSomeObject("SomeTitle2")) list_model.append(makeSomeObject("SomeTitle3")) } }