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. How to implement your own type of ListModel?

How to implement your own type of ListModel?

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

    Hello everyone,

    What I've been trying to do is creating my own personal ListModel.
    A normal List Model looks like this:

    @ListModel{
    id: myModel
    ListElement{ name:"Joe"; title: "President"}
    }@

    But I would like to add more functionality to that model and I thought of using a C++ class binding with the QML.

    Right now I have my own type of model, something like this:

    @
    MyModel
    {
    id: myModel
    nodes : [
    Node{name:"root"},
    Node{name:"child"}]
    }
    @

    But I would like to skip the "nodes" property so the syntax could be the same as in the ListModel, let's say something like this:
    @
    MyModel
    {
    Node{name:"root"}
    Node{name:"child"}
    }
    @

    Right now I am using the class QQmlListProperty, but I don't know if this class could help me do what I want. I feel like I am getting closer but hopefully someone could share some knowledge.

    Thanks in advance!

    In short, software is eating the world.

    1 Reply Last reply
    0
    • O Offline
      O Offline
      onek24
      wrote on last edited by
      #2

      Wouldn't it be enough to create a model in Cpp and pass it to QML? If it would be enough i could help you with the Cpp model but i haven't worked with creating an own QML model from QML so i might not help you with that.

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        Qnoobish
        wrote on last edited by
        #3

        I know how to create a model in C++ and pass it to QML and actually I am using C++ bindings with QML.
        I would like to do the mentioned in my post to be close to the syntax of a usual ListModel in QML, so people could follow those rules with my own Model.

        The only thing different from what I want, and I would like to remove, is that "nodes" property in MyModel.

        Thanks for your response!

        In short, software is eating the world.

        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