I have the qml list property:
Item {
property list<SomeItem> items: [
SomeItem { num: 0 },
SomeItem { num: 1 },
SomeItem { num: 2 },
...
SomeItem { num: 100 }
]
Is it possible to initialize it in more clever way? E.g. in some way like the code below?
Item {
property list<SomeItem> items
...
Component.onCompleted: {
for(var i = 0; i < 100; i++)
??? // items.append( SomeItem {num: i})
}
}
EDIT: Sorry for the id, I actually want to change my custom property (num) which is used to initialize other properties:
SomeItem {
property int num: 0
key: getKey(num)
name: getName(num)
function getKey(num) {
return ...
}
function getName(num) {
return ...
}
}
EDIT 2 (according to Mitch and ddriver answers):
I would like to use Repeater, however I have to initialize the list property which is provided by some external library.
I've been initializing SomeItem with num property because the key property must be unique and not null. However let's say I can cope with it by setting the num in onCompleted method:
Item {
property list<SomeItem> items: [
SomeItem { },
SomeItem { },
SomeItem { },
...
SomeItem { }
]
...
Component.onCompleted: {
for(var i = 0; i < items.length; i++)
items[i].num = i
}
}
So the main problem is that I have to add the SomeItem {}, line 100 times. Is there any clever way to create such property list dynamically?
ids, that's the right way indeed. The problem is maybe in the fact that he shouldn't care about them for his case, but from the example I cannot say that. - skypjackids, please answer the question for I'm curious as well and I'll vote up it for sure. - skypjack