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. Changing model for a ListView

Changing model for a ListView

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 4.2k 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.
  • H Offline
    H Offline
    huluyige
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • H Offline
        H Offline
        huluyige
        wrote on last edited by
        #3

        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]

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          Could you use a Loader component then?

          1 Reply Last reply
          0
          • H Offline
            H Offline
            huluyige
            wrote on last edited by
            #5

            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]

            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