Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
5.15.2
-
04f9219a38 (qt/qtdeclarative/dev) 04f9219a38 (qt/tqtc-qtdeclarative/dev)
Description
Observe the snippet of code below. The model is simple (not based on QAbstractItemModel), can be a number or a list. Normally, such models' data are accessed through the "modelData" property, which is automatically created when the model is simple. In this case, "modelData" is undefined.
Run the snippet with qmlscene and you get (yes, 5 times):
ReferenceError: modelData is not defined ReferenceError: modelData is not defined ReferenceError: modelData is not defined ReferenceError: modelData is not defined ReferenceError: modelData is not defined
If a descendent of the delegate, i.e. not the delegate itself, uses the "required" qualifier for a property, the view will automatically switch to the "modelData does not exist" mode, aka the "model roles are bound to required properties" mode. So what happens below, is that the presence of "required" in the MyComponent item, or any other of the delegate's descendents, which are typically completely unrelated to the model or the view at all, will cause the view to switch modes.
This may be intentional, but I think it's a bug. If the idea is that required properties are meant to automatically bind to the model's roles, this behavior makes sense only at the top level of the delegate. In descendents, if this is intended behavior, it means any item used in a delegate that has a required property needs to be careful not to use a name for that property that matches any role of the model, which breaks code locality.
import QtQuick 2.15 Item { component MyComponent: Item { required property bool foo // remove required to fix } Repeater { // replace with ListView, same fault model: 5 delegate: Item { property var foo: modelData MyComponent { foo: true } } } }
Attachments
Issue Links
- duplicates
-
QTBUG-103479 Required properties in inner elements of delegates cause views to omit model data from context
- Closed