mirror of
https://github.com/saitohirga/WSJT-X.git
synced 2024-11-25 21:58:38 -05:00
Report failed sub-process exit statuses then exit gracefully
This commit is contained in:
parent
1d6835b859
commit
98d4f771c2
@ -1,6 +1,7 @@
|
||||
//------------------------------------------------------------------ MainWindow
|
||||
#include "mainwindow.h"
|
||||
#include "revision_utils.hpp"
|
||||
#include "widgets/MessageBox.hpp"
|
||||
#include "ui_mainwindow.h"
|
||||
#include "devsetup.h"
|
||||
#include "plotter.h"
|
||||
@ -101,14 +102,15 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
SLOT(showStatusMessage(QString)));
|
||||
createStatusBar();
|
||||
|
||||
connect(&proc_m65, SIGNAL(readyReadStandardOutput()),
|
||||
this, SLOT(readFromStdout()));
|
||||
|
||||
connect(&proc_m65, SIGNAL(error(QProcess::ProcessError)),
|
||||
this, SLOT(m65_error()));
|
||||
|
||||
connect(&proc_m65, SIGNAL(readyReadStandardError()),
|
||||
this, SLOT(readFromStderr()));
|
||||
connect(&proc_m65, SIGNAL(readyReadStandardOutput()), this, SLOT(readFromStdout()));
|
||||
connect(&proc_m65, &QProcess::errorOccurred, this, &MainWindow::m65_error);
|
||||
connect(&proc_m65, static_cast<void (QProcess::*) (int, QProcess::ExitStatus)> (&QProcess::finished),
|
||||
[this] (int exitCode, QProcess::ExitStatus status) {
|
||||
if (subProcessFailed (&proc_m65, exitCode, status))
|
||||
{
|
||||
QTimer::singleShot (0, this, SLOT (close ()));
|
||||
}
|
||||
});
|
||||
|
||||
connect(&proc_editor, SIGNAL(error(QProcess::ProcessError)),
|
||||
this, SLOT(editor_error()));
|
||||
@ -1341,11 +1343,33 @@ void MainWindow::decode() //decode()
|
||||
decodeBusy(true);
|
||||
}
|
||||
|
||||
void MainWindow::m65_error() //m65_error
|
||||
bool MainWindow::subProcessFailed (QProcess * process, int exit_code, QProcess::ExitStatus status)
|
||||
{
|
||||
if (exit_code || QProcess::NormalExit != status)
|
||||
{
|
||||
QStringList arguments;
|
||||
for (auto argument: process->arguments ())
|
||||
{
|
||||
if (argument.contains (' ')) argument = '"' + argument + '"';
|
||||
arguments << argument;
|
||||
}
|
||||
MessageBox::critical_message (this, tr ("Subprocess Error")
|
||||
, tr ("Subprocess failed with exit code %1")
|
||||
.arg (exit_code)
|
||||
, tr ("Running: %1\n%2")
|
||||
.arg (process->program () + ' ' + arguments.join (' '))
|
||||
.arg (QString {process->readAllStandardError()}));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void MainWindow::m65_error (QProcess::ProcessError)
|
||||
{
|
||||
if(!m_killAll) {
|
||||
msgBox("Error starting or running\n" + m_appDir + "/m65 -s");
|
||||
exit(1);
|
||||
msgBox("Error starting or running\n" + m_appDir + "/m65 -s\n\n"
|
||||
+ proc_m65.errorString ());
|
||||
QTimer::singleShot (0, this, SLOT (close ()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1356,12 +1380,6 @@ void MainWindow::editor_error() //editor_error
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::readFromStderr() //readFromStderr
|
||||
{
|
||||
QByteArray t=proc_m65.readAllStandardError();
|
||||
msgBox(t);
|
||||
}
|
||||
|
||||
void MainWindow::readFromStdout() //readFromStdout
|
||||
{
|
||||
while(proc_m65.canReadLine())
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <QTimer>
|
||||
#include <QDateTime>
|
||||
#include <QHash>
|
||||
#include <QProcess>
|
||||
#include "getfile.h"
|
||||
#include "soundin.h"
|
||||
#include "soundout.h"
|
||||
@ -39,8 +40,7 @@ public slots:
|
||||
void diskWriteFinished();
|
||||
void freezeDecode(int n);
|
||||
void readFromStdout();
|
||||
void readFromStderr();
|
||||
void m65_error();
|
||||
void m65_error (QProcess::ProcessError);
|
||||
void editor_error();
|
||||
void guiUpdate();
|
||||
void doubleClickOnCall(QString hiscall, bool ctrl);
|
||||
@ -277,6 +277,7 @@ private:
|
||||
void ba2msg(QByteArray ba, char* message);
|
||||
void msgtype(QString t, QLineEdit* tx);
|
||||
void stub();
|
||||
bool subProcessFailed (QProcess *, int exit_code, QProcess::ExitStatus);
|
||||
};
|
||||
|
||||
extern void getfile(QString fname, bool xpol, int idInt);
|
||||
|
Loading…
Reference in New Issue
Block a user