0

Let's say I have a QtObject loaded by a Loader which is embedded in a Repeater (which itself is attached to some arbitrary ListModel).

How would I access the properties and functions of the QtObject?

Repeater {
        id: repeater
        model: listModel
        Loader {
            sourceComponent: QtObject {
                   property int width: 100
                   property int height: 100

                   function foo() {console.log("bar")}
               }
            }
        }
    }
Kenn Sebesta
  • 7,485
  • 1
  • 19
  • 21

1 Answers1

1

First you access the Loader using itemAt() function and then the QtObject using item property:

var loader = repeater.itemAt(index)
var qt_object = loader.item
console.log(qt_object)
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • I had tried exactly that, except I hadn't put it on a second line: `var fooBar = repeater.itemAt(index).item`. That seems to have been the crucial distinction, although I'm at a loss for why. What is happening differently between the two? And why does this one-liner approach fail here, but work in https://stackoverflow.com/a/20154777? – Kenn Sebesta Jul 07 '21 at 23:18
  • @KennSebesta It must be equivalent, I just wanted to be didactic in my answer. – eyllanesc Jul 07 '21 at 23:21
  • Huh. I must have been making a subtle mistake elsewhere, then. Thanks for the rapid answer, it is tested and works. – Kenn Sebesta Jul 07 '21 at 23:27