Your code is ignoring how the API was designed to work. You should use either of the alternatives presented below. Using the python
interpreter explicitly depends on whether you use the shebang properly in your python script. I have just let it in for reference, but you can easily get rid of that. It is not the main point of your issue in here.
First alternative (QStringList
based)
QProcess process;
QString scriptFile = QCoreApplication::applicationDirPath() + "../../scriptPath/script.py";
QStringList pythonCommandArguments = QStringList() << scriptFile
<< "-f " << parameter1 << "-t" << parameter2 << "-v"
<< parameter3 << "-e" << parameter4;
printf("PyCommand: %s\n", qStringToStdString(pythonCommandArguments.join(' ')).c_str());
process.start ("python", pythonCommandArguments);
Second alternative (QString
based)
QProcess process;
QString scriptFile = QCoreApplication::applicationDirPath() + "../../scriptPath/script.py";
QString pythonCommand = "python " + scriptFile +
" -f " + parameter1 +
" -t parameter2" +
" -v parameter3" +
" -e " + parameter4;
printf("PyCommand: %s\n", qStringToStdString(pythonCommand).c_str());
process.start (pythonCommand);
Here you can find the proper method signatures for both ways:
void QProcess::start(const QString & program, const QStringList & arguments, OpenMode mode = ReadWrite)
http://doc.qt.io/qt-5/qprocess.html#start
void QProcess::start(const QString & command, OpenMode mode = ReadWrite)