Important: Please read the Qt Code of Conduct -

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 :




    or even


    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":

    the correct formula is

    remember to expose the list to the QDeclarativeContext anytime you update it as explained "here":

    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