ShellCommand: Some tweaks of QtConcurrent usage

Use Utils::runAsync to avoid use of global thread pool. Move watcher
connect to constructor. Report "failure" of the command by internally
canceling.

Change-Id: Ib7616734176be2ad9356162724ca06cfd8821e52
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
Eike Ziller
2016-01-25 15:55:33 +01:00
parent d35f4fb72d
commit 4659f2caca

View File

@@ -140,7 +140,9 @@ ShellCommandPrivate::Job::Job(const QString &wd, const Utils::FileName &b, const
ShellCommand::ShellCommand(const QString &workingDirectory,
const QProcessEnvironment &environment) :
d(new Internal::ShellCommandPrivate(workingDirectory, environment))
{ }
{
connect(&d->m_watcher, &QFutureWatcher<void>::canceled, this, &ShellCommand::cancel);
}
ShellCommand::~ShellCommand()
{
@@ -223,11 +225,8 @@ void ShellCommand::execute()
if (d->m_jobs.empty())
return;
// For some reason QtConcurrent::run() only works on this
QFuture<void> task = QtConcurrent::run(&ShellCommand::run, this);
QFuture<void> task = Utils::runAsync<void>(&ShellCommand::run, this);
d->m_watcher.setFuture(task);
connect(&d->m_watcher, &QFutureWatcher<void>::canceled, this, &ShellCommand::cancel);
addTask(task);
}
@@ -305,9 +304,12 @@ void ShellCommand::run(QFutureInterface<void> &future)
}
emit finished(d->m_lastExecSuccess, d->m_lastExecExitCode, cookie());
if (d->m_lastExecSuccess)
if (d->m_lastExecSuccess) {
emit success(cookie());
future.setProgressValue(future.progressMaximum());
future.setProgressValue(future.progressMaximum());
} else {
future.cancel(); // sets the progress indicator red
}
}
if (d->m_progressParser)