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. QList as qml model
Forum Updated to NodeBB v4.3 + New Features

QList as qml model

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 293 Views 2 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.
  • C Offline
    C Offline
    Cyrille de Brebisson
    wrote on last edited by
    #1

    Hello,

    I have a property of type QList which is then used in a QML file as a model for a list view.
    When I change the various items, the QML display does change to reflect this item's change.
    But if I change the list content itself (add, remove, swap) items, there is no refresh on the QML side of things.

    I declared my property as so:
    Q_PROPERTY(QList<MyObj*> liste READ getliste)
    QList<MyObj*> _liste;
    QList<MyObj*> getliste() { return _liste; }

    Assuming that the problem was that QML was getting a COPY of the list, I tried declaring it as: QList<MyObj*> *, but QML did not seem able to handle that.

    How do I need to declare my QList so that QML will follow the changes in the model when they happen?

    Cyrille

    raven-worxR 1 Reply Last reply
    0
    • C Cyrille de Brebisson

      Hello,

      I have a property of type QList which is then used in a QML file as a model for a list view.
      When I change the various items, the QML display does change to reflect this item's change.
      But if I change the list content itself (add, remove, swap) items, there is no refresh on the QML side of things.

      I declared my property as so:
      Q_PROPERTY(QList<MyObj*> liste READ getliste)
      QList<MyObj*> _liste;
      QList<MyObj*> getliste() { return _liste; }

      Assuming that the problem was that QML was getting a COPY of the list, I tried declaring it as: QList<MyObj*> *, but QML did not seem able to handle that.

      How do I need to declare my QList so that QML will follow the changes in the model when they happen?

      Cyrille

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @Cyrille-de-Brebisson

      Q_PROPERTY(QList<MyObj*> liste READ getliste NOTIFY listeChanged)
      

      now emit the listeChanged signal everytime you change the list

      If you would implement a QAbstractListModel subclass you would have more control of rearrangements etc.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      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