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");
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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”
labela second time; you are merely assigning to it.After the assignment,
labelsimply points to an entirely different, new object, and the original object is registered for eventual deletion, so all is well.