Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
6.5.0 Beta2
-
None
-
e9f650cad (dev)
Description
I wanted to create a custom ComboBox, following the customization example:
import QtQuick.Controls
ComboBox {
id: control
delegate: MenuItem {
width: ListView.view.width
text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData
highlighted: control.highlightedIndex === index
}
}
This works with both a ListMode and a QVariantList exported from C++ as a model, but when I run this through the QML compiler, it tells me:
Warning: IconComboBox.qml:7:15: Unqualified access [unqualified] text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData ^^^^^^^ Info: Set "pragma ComponentBehavior: Bound" in order to use IDs from outer components in nested components.
Fair enough: I addde a pragma ComponentBehavior: Bound to this file and I also added the (now needed) required properties for index and modelData. Now the array / QVariantList based model works, but the ListModel based ComboBox complains at runtime:
qml: QML Component: Cannot create delegate qml: Required property modelData was not initialized (at qrc:/Mobile/IconComboBox.qml, 12)
And I get an empty popup. if I require model instead of modelData, it's the other way around.
Is there a better solution besides ignoring the qml compiler's complaint about the missing bound behavior pragma to write a generic delegate that can handle both model and modelData?
Attachments
Issue Links
- duplicates
-
QTBUG-104752 No way to support both single and multi-role models in delegates that use required properties
- Closed