From 8f4532daaebf833c87e0258f86bf25457ff29fef Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Mon, 16 Nov 2020 13:22:56 +0100 Subject: 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 --- src/plugins/coreplugin/fileutils.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'src') 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 #include #include +#include #include #include @@ -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); } } -- cgit v1.2.3