Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.7.1, 6.7.2
-
None
Description
If ListView is used as root in a custom component that requires additional properties this goes wrong.
The culprit is the following code for method getSectionItem in qquicklistview.cpp
if (delegatePriv->hadTopLevelRequiredProperties()) { delegate->setInitialProperties(nobj, {{QLatin1String("section"), section}}); } else if (!reuseExistingContext) { context->setContextProperty(QLatin1String("section"), section); }
This means that if required properties are used they are initialized. The context is not used.
Later when the section is updated with `setSectionHelper` we have a context and the lookup for the 'section' property always succeeds as the ListView is a parent that has a section property.
So the context property is updated but the required property of the delegate is left alone.
The following patch is needed:
const bool isBound = delegate->isBound(); auto delegatePriv = QQmlComponentPrivate::get(delegate); const bool useRequiredProperties = delegatePriv->hadTopLevelRequiredProperties(); const bool reuseExistingContext = isBound || useRequiredProperties;
That way no context is initialized when the required properties are used anyways.
You can use useRequiredProperties in the conditions as well.