Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initialization of a pointer immediately after calling deleteLater()

Tags:

pointers

qt

qt4

Is it safe to immediately initialize a Qt4 pointer after calling deleteLater()? I.e. is the next code safe?

QLabel *label = new QLabel("Text");
// doing smth
label->deleteLater();
label = new QLabel("Other text");
like image 306
Ivan Akulov Avatar asked Feb 25 '12 17:02

Ivan Akulov


1 Answers

According to the documentation (which you are welcome to consult yourself in the future), your code is perfectly fine. But note that your question is wrong, since you are not "initializing" label a second time; you are merely assigning to it.

After the assignment, label simply points to an entirely different, new object, and the original object is registered for eventual deletion, so all is well.

like image 52
Kerrek SB Avatar answered Sep 22 '22 20:09

Kerrek SB