QmlPreview: Rebuild instances of inner components, don't remap by index


Instances of inner components (explicit or implicit Components) are not
always recreated when we rebuild the enclosing component. They survived
with their old binding values. Furthermore, after the rebuild we
remapped all objects still referring to the old compilation unit to the
new one, keeping their indices. If objects were added or removed in
front of them, those indices referred to unrelated objects. Rebuilding
such an object later, because its own composite type changed, applied
the unrelated object's bindings and property cache to it and crashed.

Treat the roots of inner components like any other component root.
Rebuild them in place if their index still denotes a component root in
the new compilation unit and their non-composite base type hasn't
changed. Otherwise rebuild the enclosing component, found by walking up
the QML context hierarchy, and fail if there is none. Contexts on the
way may have context objects that are not component roots at all, for
example the model items of delegates. Skip those.

Don't remap anything after a rebuild. Everything instantiated by the
old compilation unit has been recreated or rebuilt then. Whatever
survived without being rebuilt is obsolete. Retire it.

Pick-to: 6.12
Task-number: QTBUG-151189
Change-Id: I06801ffae569d585b301d9634adea1137b0e9f62
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
commit9adfda0b49979c027e13a5d330b58d487cba14b4
parent7bf29431e8ea384be9ec9dbf3583026ff73f087b
authorUlf Hermann <ulf.hermann@qt.io>
committerUlf Hermann <ulf.hermann@qt.io>
commit timeFri, 9 Oct 2026 12:46:29 +0000