diff options
author | Tobias Hunger <tobias.hunger@qt.io> | 2016-04-29 16:52:58 +0200 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@qt.io> | 2016-05-11 10:04:38 +0000 |
commit | ddefe062c73e35def585f8fc6c90a4f18e47c0f4 (patch) | |
tree | 03c3aecc501c03b92e259fe0ae1c4d472033b7e5 /src/plugins/beautifier/artisticstyle/artisticstylesettings.cpp | |
parent | 1a248b1b932e2c7c42e25993d921e78c52aa4bcf (diff) |
Fix up QProcess::waitForFinished()
waitForFinish returns false if the process is no longer running at
the time of the call. Handle that throughout the codebase.
Change-Id: Ia7194095454e82efbd4eb88f2d55926bdd09e094
Reviewed-by: hjk <hjk@theqtcompany.com>
Diffstat (limited to 'src/plugins/beautifier/artisticstyle/artisticstylesettings.cpp')
-rw-r--r-- | src/plugins/beautifier/artisticstyle/artisticstylesettings.cpp | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/plugins/beautifier/artisticstyle/artisticstylesettings.cpp b/src/plugins/beautifier/artisticstyle/artisticstylesettings.cpp index c3293afbb8..ea7ea11431 100644 --- a/src/plugins/beautifier/artisticstyle/artisticstylesettings.cpp +++ b/src/plugins/beautifier/artisticstyle/artisticstylesettings.cpp @@ -32,11 +32,11 @@ #include <coreplugin/icore.h> #include <utils/runextensions.h> +#include <utils/synchronousprocess.h> #include <QDateTime> #include <QFile> #include <QFileInfo> -#include <QProcess> #include <QXmlStreamWriter> namespace Beautifier { @@ -78,18 +78,17 @@ static int parseVersion(const QString &text) static int updateVersionHelper(const QString &command) { - QProcess process; - process.start(command, {"--version"}); - if (!process.waitForFinished()) { - process.kill(); + Utils::SynchronousProcess process; + Utils::SynchronousProcessResponse response + = process.run(command, QStringList() << QLatin1String("--version")); + if (response.result != Utils::SynchronousProcessResponse::Finished) return 0; - } // Astyle prints the version on stdout or stderr, depending on platform - const int version = parseVersion(QString::fromUtf8(process.readAllStandardOutput()).trimmed()); + const int version = parseVersion(response.stdOut.trimmed()); if (version != 0) return version; - return parseVersion(QString::fromUtf8(process.readAllStandardError()).trimmed()); + return parseVersion(response.stdErr.trimmed()); } void ArtisticStyleSettings::updateVersion() @@ -155,10 +154,11 @@ QString ArtisticStyleSettings::documentationFilePath() const void ArtisticStyleSettings::createDocumentationFile() const { - QProcess process; - process.start(command(), {"-h"}); - process.waitForFinished(2000); // show help should be really fast. - if (process.error() != QProcess::UnknownError) + Utils::SynchronousProcess process; + process.setTimeoutS(2); + Utils::SynchronousProcessResponse response + = process.run(command(), QStringList() << QLatin1String("-h")); + if (response.result != Utils::SynchronousProcessResponse::Finished) return; QFile file(documentationFilePath()); @@ -176,8 +176,7 @@ void ArtisticStyleSettings::createDocumentationFile() const stream.writeStartElement(Constants::DOCUMENTATION_XMLROOT); // astyle writes its output to 'error'... - const QStringList lines = QString::fromUtf8(process.readAllStandardError()) - .split('\n'); + const QStringList lines = response.stdErr.split(QLatin1Char('\n')); QStringList keys; QStringList docu; for (QString line : lines) { |