Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Changing model for a ListView

    QML and Qt Quick
    2
    5
    3893
    Loading More Posts
    • 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
      huluyige last edited by

      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 Reply Quote 0
      • A
        andre last edited by

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

        1 Reply Last reply Reply Quote 0
        • H
          huluyige last edited by

          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 Reply Quote 0
          • A
            andre last edited by

            Could you use a Loader component then?

            1 Reply Last reply Reply Quote 0
            • H
              huluyige last edited by

              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 Reply Quote 0
              • First post
                Last post