Details
-
Bug
-
Resolution: Fixed
-
P1: Critical
-
5.15
-
None
-
566e5e1ac (dev), e9f650cad (dev)
Description
https://doc.qt.io/qt-6/qtquick-modelviewsdata-modelview.html says:
Models that do not have named roles (such as the ListModel shown below) will have the data provided via the modelData role. The modelData role is also provided for models that have only one role. In this case the modelData role contains the same data as the named role.
It then says:
Note: model, index, and modelData roles are not accessible if the delegate contains required properties, unless it has also required properties with matching names.
The problem with this is that e.g. ComboBox needs to support all kinds of models:
T.ComboBox { id: control // ... delegate: ItemDelegate { // ... text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData // ... }
So if we declare required properties for model and modelData, we get an error (depending on what type of model is in use):
qrc:/CustomComboBox.qml:8:15: QML Component: Cannot create delegate qrc:/CustomComboBox.qml:22:9: Required property modelData was not initialized
Attachments
Issue Links
- is duplicated by
-
QTBUG-110980 ComponentBehavior: Bound and generic delegates don't mix well
- Closed
-
QTBUG-111176 Views pass either "model" or "modelData" to delegates, depending on type of model
- Closed