Utils: Add TerminalMode::Detached

Change-Id: Ic36845d3469719e17f24602ce80f3e6cfc984fbf
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Marcus Tillmanns
2023-05-04 08:09:40 +02:00
parent a059f87754
commit e6081aaa0a
12 changed files with 140 additions and 110 deletions

View File

@@ -106,6 +106,8 @@ static QStringList replImportArgs(const FilePath &pythonFile, ReplType type)
void openPythonRepl(QObject *parent, const FilePath &file, ReplType type)
{
Q_UNUSED(parent)
static const auto workingDir = [](const FilePath &file) {
if (file.isEmpty()) {
if (Project *project = ProjectManager::startupProject())
@@ -116,23 +118,21 @@ void openPythonRepl(QObject *parent, const FilePath &file, ReplType type)
};
const auto args = QStringList{"-i"} + replImportArgs(file, type);
auto process = new Process(parent);
process->setTerminalMode(TerminalMode::On);
const FilePath pythonCommand = detectPython(file);
process->setCommand({pythonCommand, args});
process->setWorkingDirectory(workingDir(file));
const QString commandLine = process->commandLine().toUserOutput();
QObject::connect(process, &Process::done, process, [process, commandLine] {
if (process->error() != QProcess::UnknownError) {
Core::MessageManager::writeDisrupting(Tr::tr(
(process->error() == QProcess::FailedToStart)
? "Failed to run Python (%1): \"%2\"."
: "Error while running Python (%1): \"%2\".")
.arg(commandLine, process->errorString()));
}
process->deleteLater();
});
process->start();
Process process;
process.setCommand({pythonCommand, args});
process.setWorkingDirectory(workingDir(file));
process.setTerminalMode(TerminalMode::Detached);
process.start();
if (process.error() != QProcess::UnknownError) {
Core::MessageManager::writeDisrupting(
Tr::tr((process.error() == QProcess::FailedToStart)
? "Failed to run Python (%1): \"%2\"."
: "Error while running Python (%1): \"%2\".")
.arg(process.commandLine().toUserOutput(), process.errorString()));
}
}
QString pythonName(const FilePath &pythonPath)