Ok, creating the objects in QML is the way I like best.
Creating them works fine but now I cannot access them when I want to destroy() them.
I would need some list to keep track of them but the things I tried are not working.
(using var rects = new Array() with push() does not work, because I"m not in a Script Element and having a Javascript for each dynamic list I want to keep seems overkill)
and using property list<Rectangle> rects and append() does not work, because the list always seems to be empty).
Here a small code example:
// init a global list here
Connections {
target: ticker
onTick: {
if (t%2 == 0) {
var comp = Qt.createComponent("Rect.qml") //can I use the Rectangle type directly somehow?
var new_rect = comp.createObject(page, {"x":50, "y":50})
// alternatively
// var new_rect = Qt.createQmlObject('import QtQuick 1.0; Rectangle {color: "red"; width: 20; height: 20}', page);
// add to list
}
else {
// destroy() all rects and clear list here
}
}
}
// init a global list here
Connections {
target: ticker
onTick: {
if (t%2 == 0) {
var comp = Qt.createComponent("Rect.qml") //can I use the Rectangle type directly somehow?
var new_rect = comp.createObject(page, {"x":50, "y":50})
// alternatively
// var new_rect = Qt.createQmlObject('import QtQuick 1.0; Rectangle {color: "red"; width: 20; height: 20}', page);
// add to list
}
else {
// destroy() all rects and clear list here
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks