Important: Please read the Qt Code of Conduct -

Javascript, main QML and ListModel in another file

  • to update the ListModel from javascript i would usually do this: listmodelid.append({data}) but what if the ListModel, Component and ListView is in separete qml file called List.gml and is injected into main qml as a List { id: mylist } i was trying through mylist.listmodelid.append({data}), mylist.children.append({data})... but nothing works, lemme know if you know how to do this

  • maybe im at the wrong path, im trying to make my main qml more readable I have three similar listviews and wondering if and how to share one Component between each other, lets say Component is another file Component.qml

  • I suggest you have the ListModel, Component and ListView in three different .qml files. That way you can, for example, create an instance of your custom ListModel as MyListModel { id: listModel } and then call listModel.append({data}).

    Trying to access a child item of another component (like mylist.listmodelid) won't work unless you create a property in that component that references that child - for example, adding something like "property alias listmodelid : listmodelid" to the root object of that component. However it would be much better to just place the different types in three separate files so you can create those objects individually.

Log in to reply