
Originally Posted by
ChrisW67
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:
connect(process, SIGNAL(finished(...)), &loop, SLOT(quit()));
loop.exec();
QEventLoop loop;
connect(process, SIGNAL(finished(...)), &loop, SLOT(quit()));
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
connect(process, SIGNAL(finished(...)), &loop, SLOT(quit()));
process.start();
loop.exec()
QProcess process;
QEventLoop loop;
connect(process, SIGNAL(finished(...)), &loop, SLOT(quit()));
process.start();
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
bool processFinished = false;
connect(process, &QProcess::finished,
[&loop, &processFinished]()
{
processFinished = true;
if ( loop.isRunning() )
loop.exit();
}
)
process.start();
loop.exec()
QProcess process;
QEventLoop loop;
bool processFinished = false;
connect(process, &QProcess::finished,
[&loop, &processFinished]()
{
processFinished = true;
if ( loop.isRunning() )
loop.exit();
}
)
process.start();
loop.exec()
To copy to clipboard, switch view to plain text mode
Bookmarks