QObject Pointer deleteLater() Question
-
wrote on 6 Oct 2021, 01:42 last edited by
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 -
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,
Richwrote on 6 Oct 2021, 01:44 last edited by@Rich-Bair Silly question: why don't you just reuse QProcess?
-
wrote on 6 Oct 2021, 01:52 last edited by
@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()?
-
@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()?
wrote on 6 Oct 2021, 04:34 last edited by@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.
1/4