Fix Qt 5.15 deprecations

This commit is contained in:
Syping 2020-10-14 23:14:33 +02:00
parent 2cef92e61f
commit a9fb05c5a9
5 changed files with 35 additions and 31 deletions

View file

@ -8,7 +8,7 @@ set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON) set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt5 COMPONENTS Network REQUIRED) find_package(Qt5 COMPONENTS Network REQUIRED)

View file

@ -20,6 +20,7 @@
#include <QTextStream> #include <QTextStream>
#include "SMSubProcess.h" #include "SMSubProcess.h"
#include "smsub.h" #include "smsub.h"
#include <QDebug>
SMSubProcess::SMSubProcess(const QString &executable, const QStringList &arguments, const QString &workingDirectory, const int &termTimeout) : SMSubProcess::SMSubProcess(const QString &executable, const QStringList &arguments, const QString &workingDirectory, const int &termTimeout) :
termTimeout(termTimeout) termTimeout(termTimeout)
@ -35,7 +36,11 @@ SMSubProcess::SMSubProcess(const QString &executable, const QStringList &argumen
// Connect process signal handlers // Connect process signal handlers
QObject::connect(&process, &QProcess::readyRead, this, &SMSubProcess::readyRead); QObject::connect(&process, &QProcess::readyRead, this, &SMSubProcess::readyRead);
QObject::connect(&process, &QProcess::errorOccurred, this, &SMSubProcess::processError); QObject::connect(&process, &QProcess::errorOccurred, this, &SMSubProcess::processError);
QObject::connect(&process, QOverload<int>::of(&QProcess::finished), this, &SMSubProcess::processExit); QObject::connect(&process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), [=](int exitCode) {
// Exit with the same exit code as the process
emit processStopped();
QCoreApplication::exit(exitCode);
});
} }
void SMSubProcess::start() void SMSubProcess::start()
@ -52,22 +57,15 @@ void SMSubProcess::readyRead()
} }
} }
void SMSubProcess::processExit(int exitCode)
{
// Exit with the same exit code as the process
emit processStopped();
QCoreApplication::exit(exitCode);
}
void SMSubProcess::processError(QProcess::ProcessError error) void SMSubProcess::processError(QProcess::ProcessError error)
{ {
// Handle process errors // Handle process errors
if (likely(error == QProcess::FailedToStart)) { if (likely(error == QProcess::FailedToStart)) {
QTextStream(stderr) << "Process failed to start!" << endl; QTextStream(stderr) << "Process failed to start!" << smsub_endl;
QCoreApplication::exit(1); QCoreApplication::exit(1);
} }
else if (error == QProcess::UnknownError) { else if (error == QProcess::UnknownError) {
QTextStream(stderr) << "Unknown error occurred!" << endl; QTextStream(stderr) << "Unknown error occurred!" << smsub_endl;
QCoreApplication::exit(1); QCoreApplication::exit(1);
} }
} }
@ -78,7 +76,7 @@ void SMSubProcess::aboutToQuit()
if (process.state() == QProcess::Running) { if (process.state() == QProcess::Running) {
process.terminate(); process.terminate();
if (!process.waitForFinished(termTimeout)) { if (!process.waitForFinished(termTimeout)) {
QTextStream(stderr) << "Failed to terminate process!" << endl; QTextStream(stderr) << "Failed to terminate process!" << smsub_endl;
} }
} }
} }

View file

@ -41,7 +41,6 @@ public slots:
private slots: private slots:
void readyRead(); void readyRead();
void processExit(int exitCode);
void processError(QProcess::ProcessError error); void processError(QProcess::ProcessError error);
signals: signals:

View file

@ -56,7 +56,7 @@ void catchUnixSignals(std::initializer_list<int> quitSignals) {
default: default:
unixSignal = QString::number(sig); unixSignal = QString::number(sig);
} }
QTextStream(stderr) << "Received Unix signal: " << unixSignal << endl; QTextStream(stderr) << "Received Unix signal: " << unixSignal << smsub_endl;
QCoreApplication::quit(); QCoreApplication::quit();
}; };
@ -121,15 +121,15 @@ int main(int argc, char *argv[])
commandLineParser.process(a); commandLineParser.process(a);
if (unlikely(commandLineParser.isSet(processManifest) && commandLineParser.isSet(processExecutable))) { if (unlikely(commandLineParser.isSet(processManifest) && commandLineParser.isSet(processExecutable))) {
QTextStream(stderr) << "You can't define a Process executable and a JSON process manifest at the same time!" << endl; QTextStream(stderr) << "You can't define a Process executable and a JSON process manifest at the same time!" << smsub_endl;
return 1; return 1;
} }
if (unlikely(commandLineParser.isSet(subprocessRemotePort) && commandLineParser.isSet(subprocessRemoteSocket))) { if (unlikely(commandLineParser.isSet(subprocessRemotePort) && commandLineParser.isSet(subprocessRemoteSocket))) {
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
QTextStream(stderr) << "You can't define a WebSockets port and a IPC socket at same time!" << endl; QTextStream(stderr) << "You can't define a WebSockets port and a IPC socket at same time!" << smsub_endl;
#else #else
QTextStream(stderr) << "You can't define a WebSockets port and a Unix socket at same time!" << endl; QTextStream(stderr) << "You can't define a WebSockets port and a Unix socket at same time!" << smsub_endl;
#endif #endif
return 1; return 1;
} }
@ -158,14 +158,14 @@ int main(int argc, char *argv[])
if (likely(jsonObject.contains("Executable"))) { if (likely(jsonObject.contains("Executable"))) {
const QJsonValue jsonExecutable = jsonObject.value("Executable"); const QJsonValue jsonExecutable = jsonObject.value("Executable");
if (unlikely(!jsonExecutable.isString())) { if (unlikely(!jsonExecutable.isString())) {
QTextStream(stderr) << "Executable is not a string in manifest, aborting!" << endl; QTextStream(stderr) << "Executable is not a string in manifest, aborting!" << smsub_endl;
manifestFile.close(); manifestFile.close();
return 1; return 1;
} }
executable = jsonExecutable.toString(); executable = jsonExecutable.toString();
} }
else { else {
QTextStream(stderr) << "Executable is not defined in manifest, aborting!" << endl; QTextStream(stderr) << "Executable is not defined in manifest, aborting!" << smsub_endl;
manifestFile.close(); manifestFile.close();
return 1; return 1;
} }
@ -173,7 +173,7 @@ int main(int argc, char *argv[])
if (likely(jsonObject.contains("WorkingDirectory"))) { if (likely(jsonObject.contains("WorkingDirectory"))) {
const QJsonValue jsonWorkingDirectory = jsonObject.value("WorkingDirectory"); const QJsonValue jsonWorkingDirectory = jsonObject.value("WorkingDirectory");
if (unlikely(!jsonWorkingDirectory.isString())) { if (unlikely(!jsonWorkingDirectory.isString())) {
QTextStream(stderr) << "Working Directory is not a string in manifest, aborting!" << endl; QTextStream(stderr) << "Working Directory is not a string in manifest, aborting!" << smsub_endl;
manifestFile.close(); manifestFile.close();
return 1; return 1;
} }
@ -195,7 +195,7 @@ int main(int argc, char *argv[])
} }
} }
else { else {
QTextStream(stderr) << "Arguments is not a array in manifest, aborting!" << endl; QTextStream(stderr) << "Arguments is not a array in manifest, aborting!" << smsub_endl;
manifestFile.close(); manifestFile.close();
return 1; return 1;
} }
@ -207,7 +207,7 @@ int main(int argc, char *argv[])
termTimeout = qRound(jsonTimeout.toDouble()); termTimeout = qRound(jsonTimeout.toDouble());
} }
else { else {
QTextStream(stderr) << "Termination Timeout is not a number in manifest, aborting!" << endl; QTextStream(stderr) << "Termination Timeout is not a number in manifest, aborting!" << smsub_endl;
return 1; return 1;
} }
} }
@ -216,7 +216,7 @@ int main(int argc, char *argv[])
} }
} }
else if (unlikely(commandLineParser.isSet(processArguments))) { else if (unlikely(commandLineParser.isSet(processArguments))) {
QTextStream(stderr) << "Arguments over command line are not supported yet!" << endl; QTextStream(stderr) << "Arguments over command line are not supported yet!" << smsub_endl;
return 1; return 1;
} }
@ -226,9 +226,9 @@ int main(int argc, char *argv[])
} }
else { else {
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
QTextStream(stderr) << "You must define at least a local IPC socket!" << endl; QTextStream(stderr) << "You must define at least a local IPC socket!" << smsub_endl;
#else #else
QTextStream(stderr) << "You must define at least a local Unix socket!" << endl; QTextStream(stderr) << "You must define at least a local Unix socket!" << smsub_endl;
#endif #endif
return 1; return 1;
} }
@ -239,9 +239,9 @@ int main(int argc, char *argv[])
SMSubServer subLocal(&localSettings, socket); SMSubServer subLocal(&localSettings, socket);
if (unlikely(!subLocal.isListening())) { if (unlikely(!subLocal.isListening())) {
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
QTextStream(stderr) << "Failed to start local IPC socket!" << endl; QTextStream(stderr) << "Failed to start local IPC socket!" << smsub_endl;
#else #else
QTextStream(stderr) << "Failed to start local Unix socket!" << endl; QTextStream(stderr) << "Failed to start local Unix socket!" << smsub_endl;
#endif #endif
return 1; return 1;
} }
@ -257,7 +257,7 @@ int main(int argc, char *argv[])
bool ok; bool ok;
rport = commandLineParser.value(subprocessRemotePort).toUShort(&ok); rport = commandLineParser.value(subprocessRemotePort).toUShort(&ok);
if (!ok) { if (!ok) {
QTextStream(stderr) << "WebSockets port is not valid!" << endl; QTextStream(stderr) << "WebSockets port is not valid!" << smsub_endl;
return 1; return 1;
} }
else { else {
@ -275,9 +275,9 @@ int main(int argc, char *argv[])
SMSubServer *subRemote = new SMSubServer(&remoteSettings, rsocket); SMSubServer *subRemote = new SMSubServer(&remoteSettings, rsocket);
if (unlikely(!subRemote->isListening())) { if (unlikely(!subRemote->isListening())) {
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
QTextStream(stderr) << "Failed to start remote IPC socket!" << endl; QTextStream(stderr) << "Failed to start remote IPC socket!" << smsub_endl;
#else #else
QTextStream(stderr) << "Failed to start remote Unix socket!" << endl; QTextStream(stderr) << "Failed to start remote Unix socket!" << smsub_endl;
#endif #endif
return 1; return 1;
} }
@ -291,7 +291,7 @@ int main(int argc, char *argv[])
else if (unlikely(rportSet)) { else if (unlikely(rportSet)) {
SMSubServer *subRemote = new SMSubServer(&remoteSettings, QString(), rport); SMSubServer *subRemote = new SMSubServer(&remoteSettings, QString(), rport);
if (unlikely(!subRemote->isListening())) { if (unlikely(!subRemote->isListening())) {
QTextStream(stderr) << "Failed to start remote WebSockets server!" << endl; QTextStream(stderr) << "Failed to start remote WebSockets server!" << smsub_endl;
return 1; return 1;
} }
localSettings.canRegister = true; localSettings.canRegister = true;

View file

@ -18,6 +18,7 @@
#ifndef SMSUB_H #ifndef SMSUB_H
#define SMSUB_H #define SMSUB_H
#include <QtGlobal>
#ifndef SMSUB_WITHOUT_EXPECT #ifndef SMSUB_WITHOUT_EXPECT
#ifndef likely #ifndef likely
@ -35,4 +36,10 @@
#endif #endif
#endif #endif
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
#define smsub_endl Qt::endl
#else
#define smsub_endl endl
#endif
#endif // SMSUB_H #endif // SMSUB_H