diff options
author | Jarek Kobus <jaroslaw.kobus@qt.io> | 2020-11-16 13:22:56 +0100 |
---|---|---|
committer | Jarek Kobus <jaroslaw.kobus@qt.io> | 2020-11-17 11:31:53 +0000 |
commit | 8f4532daaebf833c87e0258f86bf25457ff29fef (patch) | |
tree | 5ca879c2cb4541e08e2f4d337174775ea1c7c813 | |
parent | 3998e30684bb8f7e81c7f51be38aa77fd351ff3d (diff) | |
download | qt-creator-8f4532daaebf833c87e0258f86bf25457ff29fef.tar.gz |
Fix warning about deprecated QProcess::startDetached()
In Qt 5.15 QProcess::startDetached(const QString &command) overload
got deprecated, and in Qt 6 it has disappeared.
We substiture it by setting explicitly the program and
arguments on browserProc. In order to properly separate
the command into program name and arguments we use
Utils::QtcProcess::splitArgs(). We also handle the case
when a path to file browser was not specified, and the case
when starting a file browser failed and the error was empty.
Task-number: QTCREATORBUG-24098
Change-Id: Ie9c9581b303407ddc5c64264576ad39ec0894bdb
Reviewed-by: hjk <hjk@qt.io>
-rw-r--r-- | src/plugins/coreplugin/fileutils.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/plugins/coreplugin/fileutils.cpp b/src/plugins/coreplugin/fileutils.cpp index 1bc9e16608..3808588da7 100644 --- a/src/plugins/coreplugin/fileutils.cpp +++ b/src/plugins/coreplugin/fileutils.cpp @@ -34,6 +34,7 @@ #include <utils/consoleprocess.h> #include <utils/environment.h> #include <utils/hostosinfo.h> +#include <utils/qtcprocess.h> #include <utils/textfileformat.h> #include <utils/unixutils.h> @@ -102,12 +103,23 @@ void FileUtils::showInGraphicalShell(QWidget *parent, const QString &pathIn) // we cannot select a file here, because no file browser really supports it... const QString folder = fileInfo.isDir() ? fileInfo.absoluteFilePath() : fileInfo.filePath(); const QString app = UnixUtils::fileBrowser(ICore::settings()); - QProcess browserProc; - const QString browserArgs = UnixUtils::substituteFileBrowserParameters(app, folder); - bool success = browserProc.startDetached(browserArgs); - const QString error = QString::fromLocal8Bit(browserProc.readAllStandardError()); - success = success && error.isEmpty(); - if (!success) + QStringList browserArgs = Utils::QtcProcess::splitArgs( + UnixUtils::substituteFileBrowserParameters(app, folder)); + QString error; + if (browserArgs.isEmpty()) { + error = QApplication::translate("Core::Internal", + "The command for file browser is not set."); + } else { + QProcess browserProc; + browserProc.setProgram(browserArgs.takeFirst()); + browserProc.setArguments(browserArgs); + const bool success = browserProc.startDetached(); + error = QString::fromLocal8Bit(browserProc.readAllStandardError()); + if (!success && error.isEmpty()) + error = QApplication::translate("Core::Internal", + "Error while starting file browser."); + } + if (!error.isEmpty()) showGraphicalShellError(parent, app, error); } } |