PDA

View Full Version : how to use setProcessEnvironment ( const QProcessEnvironment & env) in Linux?



Raul
6th June 2010, 20:07
QProcess process;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("TMPDIR", "C:\\MyApp\\temp"); // Add an environment variable
env.insert("PATH", env.value("Path") + ";C:\\Bin");
process.setProcessEnvironment(env);
process.start("myapp");

hi guys!
how to use the top codes in linux?I have tried many times.but end up with failure.what bother me was the third and fourth line.

SixDegrees
6th June 2010, 20:21
What "failure" are you talking about?

Note that QProcessEnvironment was added to Qt 4.6. What version of Qt are you using?

Raul
6th June 2010, 20:34
What "failure" are you talking about?

Note that QProcessEnvironment was added to Qt 4.6. What version of Qt are you using?

I'm using Qt 4.6.2.my problem is that i didn't understand the use of setProcessEnvironment ( const QProcessEnvironment & env) indeed.especially the insert

SixDegrees
6th June 2010, 20:39
It sets the environment variable to the value provided. It performs exactly the same function as 'setenv [name] [value]' or 'export [name]=[value]'does in the shell.

Raul
6th June 2010, 20:57
It sets the environment variable to the value provided. It performs exactly the same function as 'setenv [name] [value]' or 'export [name]=[value]'does in the shell.


If I want to start "drcomd" with QProcess,how to set the enviroment ?requesting super Konsole will be best. take my top codes for example in linux.

SixDegrees
6th June 2010, 21:11
I have no idea what 'drcomd' is, or what environment variable settings it might be expecting. If it's a console command, the documentation for it should note whatever is required to run it.

Do you know what enviornment variables are? If not, search on that term and read up on them.

Raul
6th June 2010, 21:17
I have no idea what 'drcomd' is, or what environment variable settings it might be expecting. If it's a console command, the documentation for it should note whatever is required to run it.

Do you know what enviornment variables are? If not, search on that term and read up on them.

ok! the drcomd is a console command.I just take it for example,it can be anything else console command.

SixDegrees
6th June 2010, 23:43
You need to learn what environment variables are, and what they are used for. In general, you don't need to set environment variables in order for most commands to execute properly. There are, however, exceptions, and in those cases you might need to use the setProcessEnvironment() call to provide them.

If you can execute your command at the console prompt, you probably don't need to worry about setting environment variables for it. Not understanding them, however, is likely to cause problems later.