Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Javascript, main QML and ListModel in another file
QtWS25 Last Chance

Javascript, main QML and ListModel in another file

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 2.3k Views
  • 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.
  • F Offline
    F Offline
    fgrs
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fgrs
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • B Offline
        B Offline
        blam
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved