PTBG
PTBG

Reputation: 595

Running external process from Qt program, with some changes

I have 2 programs:

program 1 - A Qt program written by me.

program 2 - A program not written by.

My goal is to run program 2 from program 1 ( I know how to do that).

My problem, however, is that program 2 has some .ini files which it looks for. It turns out that the directory program 2 looks in is not the directory of the executable, but rather the directory of the process starting the executable...in this case program 1.

so my error reads something like this:

"could not find file xxx.ini in directory C://directory of program 1//inifiles//...

my question is...is there any way I can go around this? I know it's a little confusing, so please tell me if something doesn't make sense.

Upvotes: 0

Views: 1671

Answers (2)

Wes
Wes

Reputation: 5067

If you want to find out what directory you're currently using try something like:

QDir application_dir = QDir( QDir::currentPath() );

This is quite useful for debugging purposes.

Upvotes: 0

Dave Mateer
Dave Mateer

Reputation: 17956

Assuming you are using QProcess to start program 2, you need to set the working directory by calling QProcess::setWorkingDirectory(const QString &dir).

The documentation states:

Sets the working directory to dir. QProcess will start the process in this directory. The default behavior is to start the process in the working directory of the calling process.

Upvotes: 4

Related Questions