Quote Originally Posted by ChrisW67 View Post
Lesiok's option is probably the least effort. Here are some other options:

Create a slot for each step. In the slot for step 1 start the relevant process and connect() its finished() signal to the slot for step 2... and so on. You should check the exit state of step n at the top of step n+1 before starting the new step's process.

Or, between steps:
Qt Code:
  1. connect(process, SIGNAL(finished(...)), &loop, SLOT(quit()));
  2. loop.exec();
To copy to clipboard, switch view to plain text mode 

The problem here, is you are assuming that the QProcess is still running when you start the event loop.

With the following code
Qt Code:
  1. QProcess process;
  2. connect(process, SIGNAL(finished(...)), &loop, SLOT(quit()));
  3. process.start();
  4. loop.exec()
To copy to clipboard, switch view to plain text mode 

its possible for short running executables that the process ends before the loop.exec command. This has bit me in the butt more than once.

The best solution I have come up with is the following
Qt Code:
  1. QProcess process;
  2. bool processFinished = false;
  3. connect(process, &QProcess::finished,
  4. [&loop, &processFinished]()
  5. {
  6. processFinished = true;
  7. if ( loop.isRunning() )
  8. loop.exit();
  9. }
  10. )
  11. process.start();
  12. loop.exec()
To copy to clipboard, switch view to plain text mode