Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm answering my own question because I kept working at the problem and found an acceptable solution. I'm not marking this question as answered (yet) because I would like to know if there are easier or more efficient solutions.</p> <p>Here's how I solved this problem: I used the Binding component with the Loader and created a custom MyDelegate component that has a variant property for the model's current ListElement. Here's the modified code with important changes marked by comments.</p> <p><strong>Main.qml</strong></p> <pre><code>import QtQuick 1.1 Rectangle { anchors.fill: parent width: 300 height: 200 MyGrid { anchors.fill: parent // *** Use MyDelegate rather than generic Component and refer to // *** model's properties via MyDelegate's model property internalDelegate: MyDelegate { Text { text: model.index + model.name } } internalModel: ListModel { ListElement { name: "a" } ListElement { name: "b" } } } } </code></pre> <p><strong>MyGrid.qml</strong></p> <pre><code>import QtQuick 1.1 Rectangle { id: myGrid objectName: "myGrid" property Component internalDelegate property variant internalModel GridView { anchors.fill: parent delegate: Row { Loader { id: loader sourceComponent: myGrid.internalDelegate // *** Bind current model element to the component // *** when it's loaded Binding { target: loader.item property: "model" value: model when: loader.status == Loader.Ready } } } model: parent.internalModel } } </code></pre> <p>The crucial addition is a custom MyDelegate component, which defines the model property as a variant. This binds at interpretation-time, meaning there's no error in Main.qml when the model's name property is referenced.</p> <p><strong>MyDelegate.qml</strong></p> <pre><code>import QtQuick 1.1 Rectangle { property variant model } </code></pre> <p>Something tells me there's an even easier way to do this, but this works for now.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload