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. Exposing an empty list from c++ to qml
QtWS25 Last Chance

Exposing an empty list from c++ to qml

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 2.0k Views
  • 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.
  • 5 Offline
    5 Offline
    5c2v
    wrote on last edited by
    #1

    Hello,

    I'm trying to expose a simple list to a QML UI, using the QList< QObject * > method. However, at the application's startup, the list is empty, and still the associated ListView has a count of one item (which the delegate fails to display properly, of course).

    Also, I'm not sure how I should access model's data from the delegate :

    @model.modelData.propertyName@

    or

    @theModelName.modelData.propertyName@

    or even

    @propertyName@

    Thanks in advance for any help :)

    edit : the 1st problem was a stupid mistake from me, but I'm still unsure for the second question.

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

      Hi,
      I can't help with the empty list... but on how to access the properties from QML have a look at this "example":http://qt-project.org/doc/qt-4.8/declarative-modelviews-objectlistmodel.html

      the correct formula is
      @model.modelData.propertyName@

      remember to expose the list to the QDeclarativeContext anytime you update it as explained "here":http://qt-project.org/doc/qt-4.8/qdeclarativemodels.html

      bq. Note: There is no way for the view to know that the contents of a QList have changed. If the QList changes, it will be necessary to reset the model by calling QDeclarativeContext::setContextProperty() again.

      1 Reply Last reply
      0
      • 5 Offline
        5 Offline
        5c2v
        wrote on last edited by
        #3

        Thank you very much, problem solved !

        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