QObject Pointer deleteLater() Question
-
I have a class that has a pointer member to a QProcess object (QProcess *ptr). On occasion, I need to restart the process and the flow is as follows:
- ptr->deleteLater() <<< Could have signal / slots associated with ptr QProcess
- ptr = nullptr
- ptr = new QProcess()
- connect(ptr, ....) <<< Have a few connects
- ptr set arguments for QProcess
- prt->start()
This occurs in a thread with an event loop. So as I call deleteLater() I believe Qt will track the "old" QProcess to full deletion handling any events in queue even though I'm reusing the ptr. Then my new process takes off.
Notice I'm not using the destroyed() signal and the code above occurs in a single function.
I'm chasing a crash in my application and wanted to know if this general flow has vulnerabilities I'm not seeing.
Thanks,
Rich -
@eyllanesc: Thinking about doing just that! Existing code I'm trying to investigate first.
Also, is it safer to break all connects first using disconnect(&ptr, nullptr, nullptr, nullptr) before deleteLater()?
-
@Rich-Bair said in QObject Pointer deleteLater() Question:
Also, is it safer to break all connects first using disconnect(&ptr, nullptr, nullptr, nullptr) before deleteLater()?
The QObject destructor handles disconnecting connections to and from the object.