Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QObject Pointer deleteLater() Question

QObject Pointer deleteLater() Question

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 265 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rich Bair
    wrote on last edited by
    #1

    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

    eyllanescE 1 Reply Last reply
    0
    • R Rich Bair

      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

      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by
      #2

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

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      1 Reply Last reply
      2
      • R Offline
        R Offline
        Rich Bair
        wrote on last edited by
        #3

        @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()?

        jeremy_kJ 1 Reply Last reply
        0
        • R Rich Bair

          @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()?

          jeremy_kJ Offline
          jeremy_kJ Offline
          jeremy_k
          wrote on last edited by
          #4

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

          Asking a question about code? http://eel.is/iso-c++/testcase/

          1 Reply Last reply
          2

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved