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]Accessing nested ListModel in a separate file issue...
Forum Updated to NodeBB v4.3 + New Features

[Solved]Accessing nested ListModel in a separate file issue...

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 2.1k 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

    Hello,

    I am new to Qt, so please bear with me if I am posting a silly question.

    I have a nested ListModel in a separate file as follows (I just put one element in there for brevity):

    @import QtQuick 1.0

    ListModel {
    id: topModel
    ListElement {
    mainScreen: [
    ListElement {
    title: "Settings"
    }
    ]
    }
    }
    @
    I have a separate qml file that has the ListView to access the nested "mainScreen" list as follows:

    @ListView {
    id: list2
    y: 10; width: 100; height: 100
    focus: true
    model: topModel.get(0).mainScreen
    delegate: MainScreenDelegate {}
    }
    @
    When I run it, it gives me the following error and does not show anything :

    ReferenceError: Can't find variable: topModel

    Please help me identify what I do it wrong.

    Thanks.

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

      I finally found how to make the code look correct in the post.

      Your help on the question will be really appreciated.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Kysymys
        wrote on last edited by
        #3

        I think nesting a ListModel as shown in your sample is not supported.
        You could however, store a set of models in a property:
        @
        ...
        ListModel {
        id: modelA
        ListElement { title: "Title A1" }
        ListElement { title: "Title A2" }
        }
        ListModel {
        id: modelB
        ListElement { title: "Title B1" }
        ListElement { title: "Title B2" }
        }
        property var models: [
        modelA, modelB
        ]
        ...
        ListView {
        ...
        model: models[0]
        ...
        }
        @

        See also: "ListModel":http://qt-project.org/doc/qt-5.1/qtqml/qml-qtqml-models2-listelement.html, "ListElement":http://qt-project.org/doc/qt-5.1/qtqml/qml-qtqml-models2-listelement.html, "Variant":http://qt-project.org/doc/qt-5.1/qtqml/qml-variant.html

        \o/ \o/ Kudos ...

        Paholaisen Kysymys

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

          Thanks for the reply. Appreciate it.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            Kysymys
            wrote on last edited by
            #5

            If this solved your question, please change the title so it starts with [solved] and add a solved tag.

            \o/ \o/ Kudos ...

            Paholaisen Kysymys

            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