Skip to content

SharedQmlEngine: Don't crash from dangling child item objects

In System Settings, navigating away from pushed sub-pages would often crash. The KQuickConfigModule destructor explicitly deletes SharedQmlEngine's rootObject() and implicitly its QQmlContext, but the subPages would stick around.

Before this commit, createObjectFromComponent() assigned rootObject() as QObject parent for newly instantiated objects, but not for Qt Quick items. Those would instead have the "parent" property set, i.e. setParentItem(), which does not change the QObject hierarchy.

This commit changes the logic to always call QObject::setParent(), and call the optional "parent" property setter in addition to it. This ensures that deleting rootObject() will also get rid of any otherwise dangling sub-pages.

BUG: 481045


Note that after this commit, I still see a crash (involving QQuickPopup in the QQmlEngine destructor) when ultimately closing System Settings. I don't believe it's related to this change, as I can see it before and after the commit, and on pages that don't create sub-pages at all. So my assumption is that this MR is not introducing a regression, but I welcome scrutiny.

Merge request reports