How to correctly close the subroutine started by QProcess?
-
I stumbled on the same issue as this one and found a solution:
Re: How to close the subroutine of the program started by qprocess?. The ticket was marked as solved, however, I did not find a straightforward solution, and Qt forum advised me to open a new ticket.Problem: Qt Process I launched under the hood launches other executable. After calling process.terminate(), the other executable was still active.
QProcess: Destroyed while process PATH_TO_OTHER_EXE is still running.
The solution is to call
process.waitForFinished()
(30sec timeout) or
process.waitForFinished(-1)
(waits untill closes), which waits for the subroutine to exit too. Ref: https://stackoverflow.com/questions/14504201/qprocess-and-shell-destroyed-while-process-is-still-running
After that, my issue was resolved, and I did not have to manually kill the started subroutine every time.
Hope this will be useful for somebody too:)
-
-
I stumbled on the same issue as this one and found a solution:
Re: How to close the subroutine of the program started by qprocess?. The ticket was marked as solved, however, I did not find a straightforward solution, and Qt forum advised me to open a new ticket.Problem: Qt Process I launched under the hood launches other executable. After calling process.terminate(), the other executable was still active.
QProcess: Destroyed while process PATH_TO_OTHER_EXE is still running.
The solution is to call
process.waitForFinished()
(30sec timeout) or
process.waitForFinished(-1)
(waits untill closes), which waits for the subroutine to exit too. Ref: https://stackoverflow.com/questions/14504201/qprocess-and-shell-destroyed-while-process-is-still-running
After that, my issue was resolved, and I did not have to manually kill the started subroutine every time.
Hope this will be useful for somebody too:)
@alexaatm That sounds like a horrible solution as this will block your event loop.
Let me guess: you create the QProcess object on the stack and when the object goes out of scope, it is destroyed and therefore the executable is killed.
The correct solution is to make the QProcess a member variable so it stays alive when the calling function exits.
Instead the
waitForXxxx
functions you should use signals and slots to communicate with the process.Regards