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");
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With