I am trying to catch specific error codes from a windows command line application run as a QProcess.
I had an error today where the application fails: When run on the command line: echo %errorleve% returns 14001 (ERROR_SXS_CANT_GEN_ACTCTX) which is the correct error.
In my Qt application though when I call exitCode() on the QProcess that calls this application I get 0 as the return value.
Is there a way to get the correct errorle开发者_运维知识库vel of this process? I expect I'm missing something simple.
ex:
proc_->start(bridge_config_.exePath(), args);
if (proc_->state() == QProcess::NotRunning){
handleProcessFailedToStart(proc_->exitCode());
}
QProcess::start doesn't block until the process starts or even terminates. Thus when you call exitCode() right away, it won't be valid as the process didn't even start yet. You can connect to the finished() and error() signals (the non-blocking alternative, recommended in a UI application) to get the exitcode, or call waitForStarted() and/or waitForFinished() (blocks, useful in secondary non-UI threads or in CLI programs) and then exitCode().
精彩评论