Efficiency between QProcess and "system"
-
wrote on 3 Mar 2020, 02:42 last edited by
Hi
I want to know the efficiency between usingQProcess
to runbash
to do some commands and usingsystem
orpopen
to do that( include getting content from stdout ).I think
QProcess
is convenient to do that but I have no idea whetherQProcess
is more efficient thansystem
or notRegards
Mihan -
wrote on 3 Mar 2020, 03:11 last edited by Kent-Dorfman 3 Mar 2020, 03:12
If you want to manage the process asynchronously then you use QProcess. If you want to subshell process and stall the parent while the work is being done then system() works. QProcess is the "Qt" way of doing things. They both can be used for the same purpose but QProcess is more robust.
Efficiency is irrelevant since they both probably use much of the same underlying code.
-
If you want to manage the process asynchronously then you use QProcess. If you want to subshell process and stall the parent while the work is being done then system() works. QProcess is the "Qt" way of doing things. They both can be used for the same purpose but QProcess is more robust.
Efficiency is irrelevant since they both probably use much of the same underlying code.
wrote on 3 Mar 2020, 03:24 last edited byThanks, @Kent-Dorfman
I think I know how to improve my project. -
Thanks, @Kent-Dorfman
I think I know how to improve my project.wrote on 3 Mar 2020, 08:27 last edited by@Mihan
When using Qt there is no reason to prefersystem()
overQProcess
. Even @Kent-Dorfman's "stall the parent while the work is being done" can now be achieved with the one-liner conveniencestatic
function https://doc.qt.io/qt-5/qprocess.html#execute introduced a couple of releases ago if that's what you want. And unless you are doing something special withpopen()
, Qt'sQProcess
offers pipe redirection on stdin/stdout/stderr in a convenient package.
1/4