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. ListView: call method onComplete
Forum Updated to NodeBB v4.3 + New Features

ListView: call method onComplete

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

    Hey there,

    I have a problem and it seems to be a Qt bug ^^

    I have a Loader loading some qml. one of them is a MusicList.

    This music list has a ListView

    @ListView{
    id:listView
    x:140
    y:37
    width:474
    height:100
    interactive: false
    model: XmlListModel{
    id:musicListModel

            source: "xml/musicData.xml"
            query: "/PLAYLIST/SONG"
    
            XmlRole{ name:"TITLE"; query:"TITLE/string()" }
        }
        spacing:33
        delegate:TrackItem{
            trackID: index+1
            title: TITLE
        }
    
        Component.onCompleted: {
            initialize();
        }
    }@
    

    When the component (listView) is completed I would like to call initialize()

    @function initialize()
    {
    console.log("init");
    listView.positionViewAtIndex(3, ListView.Beginning);
    }@

    While running I can see the output "init" but the positioning for the listview doesnt work although I followed these instructions

    bq. Note: methods should only be called after the Component has completed. To position the view at startup, this method should be called by Component.onCompleted. For example, to position the view at the end: Component.onCompleted: positionViewAtIndex(count - 1, ListView.Beginning)

    Later while running changing the listViews position dynamically works pretty well.

    So any ideas whats happening?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bobweaver
      wrote on last edited by
      #2

      Not Sure if this is what you mean ? but you can also control the listView via onstatuschanged in the XmlListModel
      EDIT you can also add states to your listview and then uses the status of the xmllistmodel to define the states. Would be great for animations later on
      @
      Item {
      ...
      XmlListModel{
      id:musicListModel
      source: "xml/musicData.xml"
      query: "/PLAYLIST/SONG"
      XmlRole{ name:"TITLE"; query:"TITLE/string()" }
      onStatusChanged: {
      if(status === XmlListModel.Ready){
      // do your Functions here
      }
      if(status === XmlListModel.Error){console.log(errorString())}
      if(status === XmlListModel.Loading){console.log("Loading \n" + source )}
      }
      }

      ListView{
      id:listView
      x:140
      y:37
      width:474
      height:100
      interactive: false
      model: musicListModel
      spacing:33
      delegate:TrackItem{
      trackID: index+1
      title: TITLE
      }
      }
      }@

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jens
        wrote on last edited by
        #3

        The issue is that onCompleted is called on listView before any data is available in the model. In other words you are trying to position the view at row 3 when there are 0 rows available and the request is ignored. The workaround suggested by bob should work. You could also react to onCountChanged on the ListView as well.

        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