Details
-
Suggestion
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.9.0
-
None
Description
I know that the general recommendation is to create a model in C++ and export it to QML, but sometimes it's more convenient to create a list of objects directly in QML:
// Product.qml QtObject { property string name property real price property url photoUrl property color color } // main.qml Item { property <list of Product> products TableView { model: products ... } Component { id: productComponent Product {} } onSomething: { products.append(productComponent.createObject(...)) } }
The question is, what type should the 'products' property have? I believe that all types available in QML now are not suitable.
- ListModel
Its elements are not real objects, they can't have signals, functions and property bindings, property types are limited (string, number, bool).
- js array
Not strongly typed (can contain anything, not only the Product).
Does not notify a view about adding/removing elements.
- list<T>
"Objects cannot be individually added to or removed from the list once created; to modify the contents of a list, it must be reassigned to a new list."
I propose to implement a new QML data type (or adapt list<T>), which will not have the mentioned drawbacks, it should:
- Store objects of a certain type (like list<T>).
- Has a rich method set for content manipulating (QList is a good source for inspiration).
- Works with views properly (notify about changes).
Attachments
Issue Links
- relates to
-
QTBUG-60134 Support std::vector and QVector as QML models
- Open