In the case from the related QTBUG-106118, the ListView is declared before the ScrollView, so when the QObject destruction happens, it gets destroyed first. The ScrollView being destroyed causes the attached ScrollBar object to be destroyed, which causes the attached object to access the flickable (ListView) which has already been destroyed. So a workaround for the crash is to declare the ListView after the ScrollView.
With typical usage where ScrollView is used as-is, ScrollView (and hence QQuickScrollBarAttached) is destroyed before the flickable.
This patch also adds a PRINT_LISTENERS debugging helper, as item change listener crashes can be difficult to debug.
Fixes: QTBUG-106106 Pick-to: 6.2 6.4 Change-Id: I8d0d5544ea28c1f1557abdc38d48b26d21a7f1f5 Reviewed-by: Volker Hilsheimer email@example.com Reviewed-by: Shawn Rutledge firstname.lastname@example.org
Manually cherry-picked from c6f51533. Due to split repo in Qt 5 branch, second part of that patch is to be merged in qtquickcontrols2.