Efficiency between QProcess and "system"
-
Hi
I want to know the efficiency between usingQProcessto runbashto do some commands and usingsystemorpopento do that( include getting content from stdout ).I think
QProcessis convenient to do that but I have no idea whetherQProcessis more efficient thansystemor notRegards
Mihan -
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.
Thanks, @Kent-Dorfman
I think I know how to improve my project. -
Thanks, @Kent-Dorfman
I think I know how to improve my project.@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 conveniencestaticfunction 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'sQProcessoffers pipe redirection on stdin/stdout/stderr in a convenient package.