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. [Solved] Help with Counter in Delegate
Forum Updated to NodeBB v4.3 + New Features

[Solved] Help with Counter in Delegate

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

    I have this code that some what works. If I scroll through the model till the end all the minutes count down correctly. But if I don't do anything than only the minutes on the view get updated..

    I can't do the following:

    • Update Model's values
    • Start Trigger on non-visible delegates

    Any help would be appreciated.

    Video of the Problem:
    "Your text to link here...":http://www.youtube.com/watch?v=6dL3KuybwWM

    Here is the sample code:
    @import QtQuick 1.1
    import com.nokia.meego 1.0

    Page {
    tools: commonTools

    ListView {
         id: mainListView
         x: 0
         y: 70
         width: 480;
         height: 400
         clip: true
         boundsBehavior: Flickable.DragAndOvershootBounds
         cacheBuffer: 0
         snapMode: ListView.NoSnap
         orientation: ListView.Horizontal
         flickableDirection: Flickable.HorizontalFlick
         model: mainListViewXML;
         delegate:  myDelegate;
    }
    

    XmlListModel {
    id:mainListViewXML
    source: "http://nextbart.info/etd.php?station=12th";
    query: "/nextbart/etd"
    XmlRole { name: "minutes"; query: "@minutes/string()"; }

         onStatusChanged: {
                 if (status === XmlListModel.Ready)
                 {
                     // Method #2
                     updateMinutes.start()
                 }
      }
    
    
    
    
         }
    

    Timer {
    id: updateMinutes
    interval: 6000 ;
    running: false;
    repeat: true
    onTriggered: {

          var xcount = mainListViewXML.count,
              i;
    
          for (i=0; i< xcount; i++)
          {
            var xmin  = parseFloat(mainListViewXML.get(i).minutes) - 1;
              mainListViewXML.setData(i,minutes,xmin)
          }
      }
    
      }
    

    Component{
    id: myDelegate

    Item {

       width: 160;
    
                 Timer {
                     interval: 9000; running: true; repeat: true
                     onTriggered: {
                         //! Method #1 (Only Updates visible minutes)
                         var xmin  = parseFloat(trainMinutes.text) - 1;
                         trainMinutes.text = xmin;
                     }
                  }
    
                 Text {
                     id: trainMinutes
                     text: minutes
                     font.bold: true
                     color: "#000000"
                     smooth: true
                     x: 40
                     y: 70
                     width: 86
                     height: 68
                     opacity: 1
                 }
             }
    

    }
    }

    @

    Here is a sample screen of 3 numbers on the screen.

    !http://i.imgur.com/2HF3N.png(3 Numbers)!
    Note: There are lots of more trains but only these 3 get updated if you don't scroll.

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

      A couple things you could try:

      • Regarding Method 1: ListView only creates visible delegates (that is, if the model has 10 items but the ListView can only display 3 items, it will not create the other 7). If you set a large cacheBuffer value it will force creation of all the items, and the Timer in the delegate method should work.
      • Regarding Method 1: Assuming the XML data is automatically updated, you could try changing your timer to call mainListViewXML.reload(), which will pull the latest file from the network and re-parse it.

      Regards,
      Michael

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dengineer
        wrote on last edited by
        #3

        Thanks Michael, I updated the cacheBuffer based on mainListViewXML.count, which seems to be working fine now.

        @ //! Reset Buffer
        mainListView.cacheBuffer = 160*mainListViewXML.count;@

        I don't know how much the cache buffer affects the memory usage, but I would rather load the items than reload the XML.

        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