Fix Qt 5.15 deprecations
This commit is contained in:
parent
2cef92e61f
commit
a9fb05c5a9
5 changed files with 35 additions and 31 deletions
|
@ -8,7 +8,7 @@ set(CMAKE_AUTOUIC ON)
|
|||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(Qt5 COMPONENTS Network REQUIRED)
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include <QTextStream>
|
||||
#include "SMSubProcess.h"
|
||||
#include "smsub.h"
|
||||
#include <QDebug>
|
||||
|
||||
SMSubProcess::SMSubProcess(const QString &executable, const QStringList &arguments, const QString &workingDirectory, const int &termTimeout) :
|
||||
termTimeout(termTimeout)
|
||||
|
@ -35,7 +36,11 @@ SMSubProcess::SMSubProcess(const QString &executable, const QStringList &argumen
|
|||
// Connect process signal handlers
|
||||
QObject::connect(&process, &QProcess::readyRead, this, &SMSubProcess::readyRead);
|
||||
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()
|
||||
|
@ -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)
|
||||
{
|
||||
// Handle process errors
|
||||
if (likely(error == QProcess::FailedToStart)) {
|
||||
QTextStream(stderr) << "Process failed to start!" << endl;
|
||||
QTextStream(stderr) << "Process failed to start!" << smsub_endl;
|
||||
QCoreApplication::exit(1);
|
||||
}
|
||||
else if (error == QProcess::UnknownError) {
|
||||
QTextStream(stderr) << "Unknown error occurred!" << endl;
|
||||
QTextStream(stderr) << "Unknown error occurred!" << smsub_endl;
|
||||
QCoreApplication::exit(1);
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +76,7 @@ void SMSubProcess::aboutToQuit()
|
|||
if (process.state() == QProcess::Running) {
|
||||
process.terminate();
|
||||
if (!process.waitForFinished(termTimeout)) {
|
||||
QTextStream(stderr) << "Failed to terminate process!" << endl;
|
||||
QTextStream(stderr) << "Failed to terminate process!" << smsub_endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,6 @@ public slots:
|
|||
|
||||
private slots:
|
||||
void readyRead();
|
||||
void processExit(int exitCode);
|
||||
void processError(QProcess::ProcessError error);
|
||||
|
||||
signals:
|
||||
|
|
36
main.cpp
36
main.cpp
|
@ -56,7 +56,7 @@ void catchUnixSignals(std::initializer_list<int> quitSignals) {
|
|||
default:
|
||||
unixSignal = QString::number(sig);
|
||||
}
|
||||
QTextStream(stderr) << "Received Unix signal: " << unixSignal << endl;
|
||||
QTextStream(stderr) << "Received Unix signal: " << unixSignal << smsub_endl;
|
||||
QCoreApplication::quit();
|
||||
};
|
||||
|
||||
|
@ -121,15 +121,15 @@ int main(int argc, char *argv[])
|
|||
commandLineParser.process(a);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (unlikely(commandLineParser.isSet(subprocessRemotePort) && commandLineParser.isSet(subprocessRemoteSocket))) {
|
||||
#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
|
||||
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
|
||||
return 1;
|
||||
}
|
||||
|
@ -158,14 +158,14 @@ int main(int argc, char *argv[])
|
|||
if (likely(jsonObject.contains("Executable"))) {
|
||||
const QJsonValue jsonExecutable = jsonObject.value("Executable");
|
||||
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();
|
||||
return 1;
|
||||
}
|
||||
executable = jsonExecutable.toString();
|
||||
}
|
||||
else {
|
||||
QTextStream(stderr) << "Executable is not defined in manifest, aborting!" << endl;
|
||||
QTextStream(stderr) << "Executable is not defined in manifest, aborting!" << smsub_endl;
|
||||
manifestFile.close();
|
||||
return 1;
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ int main(int argc, char *argv[])
|
|||
if (likely(jsonObject.contains("WorkingDirectory"))) {
|
||||
const QJsonValue jsonWorkingDirectory = jsonObject.value("WorkingDirectory");
|
||||
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();
|
||||
return 1;
|
||||
}
|
||||
|
@ -195,7 +195,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
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();
|
||||
return 1;
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ int main(int argc, char *argv[])
|
|||
termTimeout = qRound(jsonTimeout.toDouble());
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -216,7 +216,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -226,9 +226,9 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
else {
|
||||
#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
|
||||
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
|
||||
return 1;
|
||||
}
|
||||
|
@ -239,9 +239,9 @@ int main(int argc, char *argv[])
|
|||
SMSubServer subLocal(&localSettings, socket);
|
||||
if (unlikely(!subLocal.isListening())) {
|
||||
#ifdef Q_OS_WIN
|
||||
QTextStream(stderr) << "Failed to start local IPC socket!" << endl;
|
||||
QTextStream(stderr) << "Failed to start local IPC socket!" << smsub_endl;
|
||||
#else
|
||||
QTextStream(stderr) << "Failed to start local Unix socket!" << endl;
|
||||
QTextStream(stderr) << "Failed to start local Unix socket!" << smsub_endl;
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
@ -257,7 +257,7 @@ int main(int argc, char *argv[])
|
|||
bool ok;
|
||||
rport = commandLineParser.value(subprocessRemotePort).toUShort(&ok);
|
||||
if (!ok) {
|
||||
QTextStream(stderr) << "WebSockets port is not valid!" << endl;
|
||||
QTextStream(stderr) << "WebSockets port is not valid!" << smsub_endl;
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
|
@ -275,9 +275,9 @@ int main(int argc, char *argv[])
|
|||
SMSubServer *subRemote = new SMSubServer(&remoteSettings, rsocket);
|
||||
if (unlikely(!subRemote->isListening())) {
|
||||
#ifdef Q_OS_WIN
|
||||
QTextStream(stderr) << "Failed to start remote IPC socket!" << endl;
|
||||
QTextStream(stderr) << "Failed to start remote IPC socket!" << smsub_endl;
|
||||
#else
|
||||
QTextStream(stderr) << "Failed to start remote Unix socket!" << endl;
|
||||
QTextStream(stderr) << "Failed to start remote Unix socket!" << smsub_endl;
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
@ -291,7 +291,7 @@ int main(int argc, char *argv[])
|
|||
else if (unlikely(rportSet)) {
|
||||
SMSubServer *subRemote = new SMSubServer(&remoteSettings, QString(), rport);
|
||||
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;
|
||||
}
|
||||
localSettings.canRegister = true;
|
||||
|
|
7
smsub.h
7
smsub.h
|
@ -18,6 +18,7 @@
|
|||
|
||||
#ifndef SMSUB_H
|
||||
#define SMSUB_H
|
||||
#include <QtGlobal>
|
||||
|
||||
#ifndef SMSUB_WITHOUT_EXPECT
|
||||
#ifndef likely
|
||||
|
@ -35,4 +36,10 @@
|
|||
#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
|
||||
|
|
Loading…
Reference in a new issue