[Qt-creator] Utils::QtcProcess

Jaroslaw Kobus Jaroslaw.Kobus at qt.io
Tue Feb 14 22:02:46 CET 2023

>> 2. When using QtcProcess it is also safe to destruct it while underlaying
>> QProcess is still being run. QtcProcess takes care about safe termination
>> through Utils::ProcessReaper in the background.
> What does this do other than terminating the process? How is this more safe?
> Can/should this be upstreamed to QtCore if it's such a general important
> improvement?

When you destruct running QProcess, it:
1. Prints a warning
2. Calls kill()
3. Calls blocking waitForFinished() - this may possibly block your UI thread for longer time.

When you destruct running QtcProcess, it:
1. Doesn't print a warining
2. Moves a running process into another thread (ProcessReaper's thread)
3. Calls terminate (a gentle way of stopping the process)
4. After desired time (500ms by default), when process didn't finish, it calls kill()
5. The destructor of QtcProcess doesn't block at all.
6. When the ProcessReaper is being destructed (when leaving main() function) it waits until all processes being reaped are finished inside a ProcessReaper.

Not sure if the above solution may be easily adopted by QProcess, as the latter is designed to work also without an event loop, while the current implementation of ProcessReaper relies on having spinning event loop. However, maybe it can be easily bypassed somehow. Feel free to open a ticket for QProcess feature, if you find it useful.


More information about the Qt-creator mailing list