Changing model for a ListView



  • Hi everyone,

    I got a ListView and some models for it. Each model is in independente QML files.

    I use
    @model: MyModel1{} @

    to intitialize the model for the view.

    My question is: when i want to changing models, (for example, there is a button doing it ), i cant use

    @OnClicked:{
    myList.model=MyModel2{}
    }@

    there is going to be an error, How can i do it?
    Ps, I can't write all the model in the ListView 's QML file, because i want a dynamical way to change model, and i dont know i will have my many models at the beginning.

    Thanks



  • You can assign new models by their id's, AFAIK. Would that be an acceptable solution for you?



  • Thanks, but the ListModel is in another QML file, the id property is unique in one QML file, isn't it?
    [quote author="Andre" date="1301315531"]You can assign new models by their id's, AFAIK. Would that be an acceptable solution for you?[/quote]



  • Could you use a Loader component then?



  • Thanks Andre,

    I changed the structure of my application: i used QML to create a ListModel before, it was not that convinent, because my application is very dynamic. Now, I create models using Qt/C++, and expose the model to QML.

    [quote author="Andre" date="1301318630"]Could you use a Loader component then?[/quote]


Log in to reply
 

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