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]Get ListModel count outside of delegate...
Forum Updated to NodeBB v4.3 + New Features

[Solved]Get ListModel count outside of delegate...

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

    Is there a way to get the count of a ListModel outside of the delegate? For instance, I have a ListModel below in a qml file, say SampleModel.qml:

    @ListModel {
    id: sampleModel
    ListElement {name: "1"}
    ListElement {name: "2"}
    ListElement {name: "3"}
    ListElement {name: "4"}
    }
    @

    How do I get the count property of the sampleModel from another qml file, main.qml, without using ListView or GridView etc.? I tried the main.qml like this (the SampleModel is in the same directory the main.qml), but it gives the error "ReferenceError: Can't find variable: sampleModel".

    @import QtQuick 1.0

    Rectangle {
    id: main_window
    x: 0; y:0

    Text {
    text: sampleModel.count
    }
    }
    @

    Thanks.

    1 Reply Last reply
    0
    • V Offline
      V Offline
      Vincent007
      wrote on last edited by
      #2

      @
      Rectangle {
      id: main_window
      x: 0; y:0

      SampleModel {
      id: myModel
      }

      Text {
      text: myModel.count
      }
      }
      @

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qt-achieve
        wrote on last edited by
        #3

        Thanks for your quick response! I am impressed by the speed I can get help from this forum.

        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