Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
175
rated 0 times [  178] [ 3]  / answers: 1 / hits: 16762  / 10 Years ago, wed, july 30, 2014, 12:00:00

When I need to create any QML component in runtime, I can use that guide:
http://qt-project.org/doc/qt-5/qtqml-javascript-dynamicobjectcreation.html



i.e. just call Qt.createComponent and component.createObject



But I couldn't find how to create ListModel at runtime? with qml, not in c++.



You can ask, why I need it. So, I have a nested ListModel: there is outer model, which delegates contained inner models. So when I'm calling outer_model.append({}), I must pass newly created ListModel for inner model. I cannot use statically defined inner model in outer delegate, because I cannot access such model in runtime. By the way, can it be accessed somehow?



P.S. Maybe it's completely wrong idea to try managing models in javascript?


More From » runtime

 Answers
31

Try this:



Component {
id: someComponent
ListModel {
}
}

function createModel(parent) {
var newModel = someComponent.createObject(parent);
return newModel;
}

[#69998] Sunday, July 27, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alejandro

Total Points: 231
Total Questions: 102
Total Answers: 107

Location: Jordan
Member since Wed, Jun 17, 2020
4 Years ago
alejandro questions
Mon, Jul 18, 22, 00:00, 2 Years ago
Fri, Sep 18, 20, 00:00, 4 Years ago
Thu, Sep 10, 20, 00:00, 4 Years ago
;