PDA

View Full Version : QProcess setEnvirontment fails



nkpatro
28th May 2021, 02:58
Hi
I am working on a application launcher and using QProcess to Launch the application. However, QProcess is failing to set the environment.
The application launches without a license.

Here is the version of code.



void MainWindow::appItemClicked(const QString &appName)
{
QJsonObject jo = getApplicationInfo(appName);
auto joEnv = jo.value(QString("env")).toObject();
auto joBin = jo.value(QString("bin")).toArray();

QStringList args;
foreach (auto val, joBin)
args << val.toString();

auto env = QProcess::systemEnvironment();
foreach (auto key, joEnv.keys())
{
auto newValue = joEnv.value(key).toString();
env.insert(key, newValue);
}
QProcess process;
process.setProgram(args[0]);
args.pop_front();
if (args.count() > 0)
process.setArguments(args);
process.setProcessEnvironment(env);
process.startDetached();
process.waitForFinished(-1);
}


getApplicationInfo () returns this data


{
"env": {
"FOUNDRY_LOG_FILE": "/Scratch/log/nuke/nuke11.log",
"RLM_LICENSE": "port@ip_address",
},
"bin": [
"/usr/local/Nuke11/Nuke",
"--nukex"
]
}



If I run the same in "/bin/bash" the application finds the license and works perfectly.
the shell script looks like this


#!/bin/bash

export FOUNDRY_LOG_FILE=~/software/Scratch/log/nuke/nuke11.log
export RLM_LICENSE=port@ip_address

/usr/local/Nuke11/Nuke --nukex


Can anyone help find where am I going wrong?

Thanks in advance.
Navin

Ginsengelf
28th May 2021, 07:13
Hi, did you check your "env" variable after the "foreach" loop to see if your additions are made, and if they are in the correct format?

Ginsengelf

ChrisW67
31st May 2021, 09:53
Line 3 of your getApplicationInfo output, an absolute path, is not the same path as line 3 of the Bash script, a path relative to your home directory. You are not likely to be able to write in that location (if it exists at all).
Are you sure the license is the problem?