[Interest] Reasons why deleteLater() might not work

Michael Jackson mike.jackson at bluequartz.net
Fri Apr 1 15:17:59 CEST 2022


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()?
--
Mike Jackson 




More information about the Interest mailing list