Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Exposing an empty list from c++ to qml

    QML and Qt Quick
    2
    3
    1782
    Loading More Posts
    • 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
      5c2v last edited by

      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 Reply Quote 0
      • U
        ultimodruido last edited by

        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 Reply Quote 0
        • 5
          5c2v last edited by

          Thank you very much, problem solved !

          1 Reply Last reply Reply Quote 0
          • First post
            Last post