[Interest] Reasons why deleteLater() might not work
Michael Jackson
mike.jackson at bluequartz.net
Sat Apr 2 18:29:43 CEST 2022
That is an interesting bug. I will have to see if that situation is
similar to ours. If an object is in the middle of a signal call would
that impact deleteLater()?
We are on the main UI thread and there are no other threads (that our
application creates and uses) in the works at this point. (.. to
answer some earlier questions).
--
Mike Jackson
On Fri, Apr 1, 2022 at 11:22 AM Sérgio Martins <sergio.martins at kdab.com> wrote:
>
> On 2022-04-01 14:17, Michael Jackson wrote:
> > I have a bit of code where in I am removing a QWidget from the UI and
> > it needs to be truly cleaned up as its parent QObject is also being
> > cleaned up. I thought I did the appropriate:
> >
> > layout->removeWidget(widget);
> > widget->setParent(nullptr);
> > widget->deleteLater();
> >
> > I put a "std::cout <<... " in the widget's destructor but I never see
> > it printed. I put a break point in the destructor and the break point
> > never gets hit. Looked around on the internet, various forums, double
> > checked that the event loop is actually running, called
> > qtapp->eventLoop()->processEvents() (or whatever that bit of code is)
> > a few times. Nothing. Currently we are leaking memory because we are
> > creating the widget but never deleting the widget when it is removed
> > from the UI. I'll assume since I have complete control of the UI that
> > the event loop is running. The last line in our main() is app.exec();
> > so I am assuming the event loop is running. This was originally with a
> > self-built Qt 5.15.2 on macOS 10.15 (Catalina) but I installed the
> > normal Qt 5.15.2 from www.qt.io and it behaves the same way. I have
> > other applications where this does actually work so I am trying to
> > figure out where in this new version of the application we messed up.
> > If anyone has any thoughts on where to look I would really appreciate
> > the sanity check.
> >
> > If we are in the middle of a signal being fired would that stop the
> > deleteLater() from working?
> > Do I need to manually disconnect all signals/slots for deleteLater() to
> > work?
> > We have a mix of new style connects and old style connects? Is that
> > messing with deleteLater()?
>
>
>
> One situation I've came across in the past was:
> https://bugreports.qt.io/browse/QTBUG-83030
>
>
> Regards,
> --
> Sérgio Martins | sergio.martins at kdab.com | Senior Software Engineer
> Klarälvdalens Datakonsult AB, a KDAB Group company
> Tel: Sweden (HQ) +46-563-540090, USA +1-866-777-KDAB(5322)
> KDAB - The Qt, C++ and OpenGL Experts
More information about the Interest
mailing list