GUI: Replace deprecated QProcess::start()

The QProcess::start() method is replaced with a new one that requires
executable path and arguments passed separately.

Each argument must be now passed individualy using QStringList and
have their spaces escaped automatically and passing argument
list as a single string would no longer work. This is now handled by
splitting the argument string on spaces.

The executable path can no longer contain quotes as spaces are escaped
by QT automatically now.
This commit is contained in:
Martin Piatka
2021-02-15 13:18:12 +01:00
parent cfadea4c65
commit 71426a86da
4 changed files with 31 additions and 17 deletions

View File

@@ -35,7 +35,7 @@ int main(int argc, char *argv[]){
//important: If this line is removed parsing float numbers for vu meter fails
std::setlocale(LC_NUMERIC, "C");
process.start("\"" + ultragridExecutable + "\"");
process.start(ultragridExecutable, QStringList());
if(process.waitForStarted(1000) == false) {
QMessageBox msgBox;
msgBox.setText(ultragridExecutable + " doesn't seem to be executable.");

View File

@@ -1,5 +1,6 @@
#include <QProcess>
#include <QString>
#include <QStringList>
#include <QRegularExpression>
#include <QJsonDocument>
#include <QJsonObject>
@@ -18,9 +19,9 @@ static bool vectorContains(const std::vector<std::string> &v, const std::string
return false;
}
static QStringList getProcessOutput(const std::string& executable, const std::string& command){
static QStringList getProcessOutput(const std::string& executable, const QStringList& args){
QProcess process;
process.start((executable + command).c_str());
process.start(executable.c_str(), args);
process.waitForFinished();
QString output = QString(process.readAllStandardOutput());
@@ -30,7 +31,7 @@ static QStringList getProcessOutput(const std::string& executable, const std::st
}
void AvailableSettings::queryAll(const std::string &executable){
QStringList lines = getProcessOutput(executable, " --capabilities");
QStringList lines = getProcessOutput(executable, QStringList() << "--capabilities");
queryCap(lines, VIDEO_SRC, "[cap][capture] ");
queryCap(lines, VIDEO_DISPLAY, "[cap][display] ");

View File

@@ -12,6 +12,20 @@
#include <CoreFoundation/CoreFoundation.h>
#endif
namespace {
QString argListToString(const QStringList& argList){
return argList.join(" ");
}
QStringList argStringToList(const QString& argString){
return argString.split(" ", Qt::SkipEmptyParts);
}
QStringList argStringToList(const std::string& argString){
return QString::fromStdString(argString).split(" ", Qt::SkipEmptyParts);
}
} //anonymous namespace
UltragridWindow::UltragridWindow(QWidget *parent): QMainWindow(parent){
ui.setupUi(this);
//ui.terminal->setVisible(false);
@@ -19,7 +33,7 @@ UltragridWindow::UltragridWindow(QWidget *parent): QMainWindow(parent){
ui.actionTest->setVisible(true);
#endif //DEBUG
ultragridExecutable = "\"" + UltragridWindow::findUltragridExecutable() + "\"";
ultragridExecutable = UltragridWindow::findUltragridExecutable();
#ifndef __linux
ui.actionUse_hw_acceleration->setVisible(false);
@@ -152,13 +166,9 @@ void UltragridWindow::start(){
stopPreview();
QString command(ultragridExecutable);
command += " ";
command += launchArgs;
process.setProcessChannelMode(QProcess::MergedChannels);
log.write("Command: " + command + "\n\n");
process.start(command);
log.write("Command args: " + argListToString(launchArgs) + "\n\n");
process.start(ultragridExecutable, launchArgs);
}
void UltragridWindow::schedulePreview(){
@@ -176,8 +186,7 @@ void UltragridWindow::startPreview(){
while(previewProcess.state() != QProcess::NotRunning)
stopPreview();
QString command(ultragridExecutable);
command += QString::fromStdString(settings.getPreviewParams());
QStringList previewArgs = argStringToList(settings.getPreviewParams());
/*
if(sourceOption->getCurrentValue() != "none"){
//We prevent video from network overriding local sources
@@ -187,9 +196,9 @@ void UltragridWindow::startPreview(){
*/
#ifdef DEBUG
log.write("Preview: " + command + "\n\n");
log.write("Preview: " + argListToString(previewArgs) + "\n\n");
#endif
previewProcess.start(command);
previewProcess.start(ultragridExecutable, previewArgs);
}
void UltragridWindow::stopPreview(){
@@ -203,11 +212,14 @@ void UltragridWindow::stopPreview(){
}
void UltragridWindow::editArgs(const QString &text){
launchArgs = text;
launchArgs = argStringToList(text);
}
void UltragridWindow::setArgs(){
QString args = QString::fromStdString(settings.getLaunchParams());
launchArgs = argStringToList(args);
#ifdef DEBUG
log.write("set args: " + args + "\n");
#endif

View File

@@ -2,6 +2,7 @@
#define ULTRAGRID_WINDOW_HPP
#include <QProcess>
#include <QStringList>
#include <vector>
#include <memory>
@@ -38,7 +39,7 @@ private:
AvailableSettings availableSettings;
QString launchArgs;
QStringList launchArgs;
QStringList getOptionsForParam(QString param);
LogWindow log;
SettingsWindow settingsWindow;