I want to run a qprocess (the program adb) and when the process is finished return the results to the calling function. However, there's every possibility that adb could find itself in a loop, printing error messages such as "ADB server didn't ACK" to stdout, not ever finishing. I need to trap these errors.
connect(&run_command,SIGNAL(readyReadStandardOutput()),this,SLOT( dolog() ));
QString result=RunProcess("adb connect 192.168.1.100");
QString MainWindow::RunProcess(QString cstring)
// keep gui active for lengthy processes.
while(run_command.state() != QProcess::NotRunning)
return command; // returns nothing if slot is enabled.
QString logstring = run_command.readAllStandardOutput();
if (logstring.contains("error condition")
First you need to identify which output stream the command in question is using for its errors.
It is very like
stderr so you would need to connect to the
readyReadStandardError() signal instead.
For the command itself I would recommend to split it into command and arguments and use the
QProcess::start() overload that takes the command and a list of arguments.
Just more robust than to rely on a single string being correctly separated again.