Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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:

    1. ptr->deleteLater() <<< Could have signal / slots associated with ptr QProcess
    2. ptr = nullptr
    3. ptr = new QProcess()
    4. connect(ptr, ....) <<< Have a few connects
    5. ptr set arguments for QProcess
    6. 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



  • @Rich-Bair Silly question: why don't you just reuse QProcess?



  • @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.


Log in to reply