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. Force property binding to refresh
Forum Updated to NodeBB v4.3 + New Features

Force property binding to refresh

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

    Hello,

    I am new to QML, it's a nice addition to Qt.

    I have several Elements showing data from a XmlListModel, like this :

    @
    Page{
    id: myPage

    property XmlListModel model : XmlListModel{}
    
     Text {
          id: title
          text: model.get(0) ? model.get(0).title : ""
     }
    
     //.... other elements
    

    }
    @

    Problem: when the model update its content (after a reload() for exemple), the binded properties do not get updated whith the new data. From my understanding of QML, it should be the case, isn't it ?

    For exemple in the exemple above, the text of the title element do not show the new content in the model.
    Is there a way to force the binding to refresh ?

    Maybe this is happening because I call a function in my binding (model.get(0)), is it allowed/supported?
    How would you solve the problem ?

    Thanks

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Diph
      wrote on last edited by
      #2

      Does the model contain only one item? Maybe you can use for example Repeater and set model to XmlListModel.

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

        Hi,

        Yes, the issue in this case is the use of get() (C++ functions don't have any way to NOTIFY when the value returned is out-of-date, the way properties do).

        It's not very nice, but you can include a dummy property in the binding that can be changed to force the binding to update. For example, in the snipped below, you could change the value of dummyValue (a bool property that you declare) whenever the model is updated to force the binding to be reevaluated.

        @text: (model.get(0) && (dummyValue || !dummyValue)) ? model.get(0).title : ""@

        Regards,
        Michael

        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