Details
-
Bug
-
Resolution: Fixed
-
P1: Critical
-
5.15
-
None
-
566e5e1ac (dev), e9f650cad (dev), be884811d (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
For Gerrit Dashboard: QTBUG-104752 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
461051,33 | Models: Straighten out model and modelData properties | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |
464725,4 | moc: Allow anonymous properties | dev | qt/qtbase | Status: MERGED | +2 | 0 |
474438,3 | Models: Fix condition for context object | dev | qt/qtdeclarative | Status: MERGED | +2 | 0 |