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. How to use the source file that I passed the path in a property of the Item as model/delegate of the ListView inside the Item
Forum Updated to NodeBB v4.3 + New Features

How to use the source file that I passed the path in a property of the Item as model/delegate of the ListView inside the Item

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 853 Views 1 Watching
  • 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
    hfxc
    wrote on 25 Apr 2014, 14:50 last edited by
    #1

    Hello,

    Im trying to create an Item where I can pass as a property an string containing the path to a source file that contains the model/delegate/both and use them in the ListView inside the item

    @MyItem {
    modelSource: "MyModel1.qml"
    delegateSource: "MyDelegate1.qml"
    }
    MyItem {
    modelSource: "MyModel2.qml"
    delegateSource: "MyDelegate2.qml"
    }@

    Some stuff that i tried was

    @Loader {
    id: model
    source: modelSource
    }

    Loader {
    id: delegate
    source: delegateSource
    }

    ListView {
    model: model
    delegate: delegate
    }@

    @ListView {
    model: Qt.createComponent(modelSource)
    delegate: Qt.createComponent(delegateSource)
    }@

    And some variations of that, but none seemed to work, some return reference errors from delegate not seeing the model and others just doesnt draw anything on the screen. I also tried using VisualDataModel and loading them but same results

    Is there anyway to do what I want or I should create a few versions of the Item each one with their model/delegate?

    Thanks in advance

    1 Reply Last reply
    0
    • G Offline
      G Offline
      Gianluca
      wrote on 26 Apr 2014, 19:58 last edited by
      #2

      I'm not sure how to resolve, but looking at your solution I notice one thing:

      The model require an object (an instantiated component like ListModel, etc), while delegate require a component (not an object).

      Your first solution create two objects, so maybe delegate do not get the right thing.
      Your second solution create two components, so maybe this time is the model that do not get the right thing.

      Try to mix them.

      @
      Loader {
      id: model
      source: modelSource
      }

      ListView {
      model: model.item
      delegate: Qt.createComponent(delegateSource)
      }
      @

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hfxc
        wrote on 2 May 2014, 14:18 last edited by
        #3

        It worked! Thanks.

        But my problem now is a seg fault with a few Elements in the ListModel. With only 8 elements, I get instant seg fault when I try to run the application. Im now trying to solve it.

        Thanks again.

        1 Reply Last reply
        0

        1/3

        25 Apr 2014, 14:50

        • Login

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