Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the QObject::deleteLater() to zero the object?

Normally when I delete an object I set it to zero. This helps in that I code my routines to check the object is not zero then proceed.

However if I use the deleteLater() function I have lost control of it. I don't know if its a valid item or if I need to create a new one. The solution I found was just to keep track of the state separately however is there a better way?

like image 729
Phil Hannent Avatar asked May 23 '11 10:05

Phil Hannent


Video Answer


1 Answers

There is nothing wrong if you call deleteLater() on your object and then set your pointer to nullptr. Qt framework will safely delete the object for you.

As an alternative you can also connect to destroyed signal to be notified of your object's destruction and set your pointer to nullptr in that slot.

like image 89
O.C. Avatar answered Sep 22 '22 06:09

O.C.