Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to get ListModel from QML to a C++ class?

How to get ListModel from QML to a C++ class?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.9k 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,

    Just as my title says is there a way to send a ListModel filled in QML to a C++ class.

    I've been using some C++ bindings and Q_PROPERTY to try to achieve this but with no success.

    Hopefully there is some example on how to do this.

    Thanks in advance :O

    In short, software is eating the world.

    1 Reply Last reply
    0
    • U Offline
      U Offline
      utcenter
      wrote on last edited by
      #2

      It is a no no, you need to create your model in C++ and keep it there and only interface it to QML. You could pull the data one element at a time, but the proper way to go is use a C++ model to begin with.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        thiagocorrea
        wrote on last edited by
        #3

        There is nothing inherently wrong with it.
        You should be able to create a property that takes a QObject* and dynamic_cast it to QAbstractItemModel*.

        That is the trick when doing the other way around. When you create a model from C++ to use in QML, your function/method should return QObject*, it will not work with any of the QAbstract*Model classes that I have tried.

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

          [quote author="thiagocorrea" date="1363832522"]There is nothing inherently wrong with it.
          You should be able to create a property that takes a QObject* and dynamic_cast it to QAbstractItemModel*.

          That is the trick when doing the other way around. When you create a model from C++ to use in QML, your function/method should return QObject*, it will not work with any of the QAbstract*Model classes that I have tried.[/quote]

          Ok I think I will try your approach. Ill keep posting my results.

          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