<table><tr><td style="">davidedmundson accepted this revision.<br />davidedmundson added a comment.<br />This revision is now accepted and ready to land.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D5321" rel="noreferrer">View Revision</a></tr></table><br /><div><div><p>Heh, finally found the bug.</p>

<p>I was a bit wrong.<br />
QObject::destroyed() is emitted before we delete the children.</p>

<p>But that still doesn't explain everything, the containment won't get deleted till after the child applet is deleted; so why would containment() be null?<br />
We know it's not deleted yet, so it's not really "gone" like your comment says,</p>

<p>The issue is that containment() is a qobject_cast recursive search of parents. (for some reason)</p>

<p>qobject_cast calls metaobject() which is virtual. Calling a virtual method during an objects destructor can result in unexpected behaviour. <br />
Our parent is still valid, but we've called Containment::~Containment, Applet::~Applet  and we're currently in QObject::~QObject, so when we call a method on a base class it doesn't get dynamically dispatched as it should.</p>

<p>So when we call parent()->metaObject() we now get the metaobject for QObject not the metaobject of Containment.</p>

<p>This means the qobject_cast fails, and that's why Applet::containment() is null even though the containment is still there.</p></div></div><br /><div><strong>REPOSITORY</strong><div><div>R120 Plasma Workspace</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D5321" rel="noreferrer">https://phabricator.kde.org/D5321</a></div></div><br /><div><strong>To: </strong>broulik, Plasma, davidedmundson<br /><strong>Cc: </strong>davidedmundson, plasma-devel, progwolff, lesliezhai, ali-mohamed, jensreuterberg, abetts, sebas, apol<br /></div>