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>
This commit is contained in:
Jarek Kobus
2020-11-16 13:22:56 +01:00
parent 3998e30684
commit 8f4532daae

View File

@@ -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);
}
}