Exposing an empty list from c++ to qml



  • 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.



  • 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.



  • Thank you very much, problem solved !


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.