[Interest] QProcess overload slot connection

Jason H jhihn at gmx.com
Wed Mar 13 22:08:19 CET 2019

> > What's the "right way" to connect QProcess::finished to QEventLoop::quit?
> The one you listed above.

It turns out that I'm not even using that anymore. 

In the situation that there's a problem, you end up waiting for timeout.
connect(process,QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), &loop, &QEventLoop::quit);
connect(process, &QProcess::stateChanged,[=, &loop](QProcess::ProcessState state) {
	qDebug() << "stateCanged" << state;
	if (state == QProcess::ProcessState::NotRunning) loop.quit();

Because the NotRunning will occur always, and immediately, and finished won't.
Failed command:
stateCanged QProcess::Starting
stateCanged QProcess::NotRunning
// no finished!

Successful command:
stateCanged QProcess::Starting
stateCanged QProcess::Running
stateCanged QProcess::NotRunning
finished 0 QProcess::NormalExit

More information about the Interest mailing list