PDA

View Full Version : How to change working directory



rakeshthp
1st December 2015, 11:44
Hi,

There is an option in Qt Creator. In any project, we have build configurations and run configurations. After changing it to run tab, we see there is a working directory option. It is easy to change the working directory through this project options interface. Is it possible to achieve the same using some variables in .pro file? Qt experts kindly give your comments on the same.

Thanks in advance.

Rakesh Patil

Vikram.Saralaya
1st December 2015, 12:11
As you mentioned you can change the working directory through the Run configuration.

In .pro file $$PWD refers to this working directory. If you wan't to refer to a different path you can define a relative path w.r.t this. eg $$PWD/../../Folder2LevelUp/..

rakeshthp
1st December 2015, 12:34
Hi,

The present scenario is that I have my compiled and linked application in %{buildDir}\release folder. The same is Working Directory showing in Run options in project tab. I have additional dlls in some other folder. Now when I run the application through QT creator, it needs these DLLs. So what I do is I give the path of DLL files as working directory in the interface. So then my application runs through Qt creator.

If I take this folder on another system, build & run configurations get reset with default values and not the one which I have set through interface. So, I thought it can be done using .pro file. Is there any way to achieve this?

Thanks in advance.

Vikram.Saralaya
1st December 2015, 12:52
Ahh ok, you need DESTDIR variable in the pro file to point to a specific folder always. Example:


DESTDIR = $$PWD/../../Runtime/Bin

rakeshthp
1st December 2015, 13:20
Hi,

By doing that only executable file will be stored in that Bin. So, you expect me to keep these DLLs in the Bin folder also? or set DESTDIR to dll folder?

Thanks

Vikram.Saralaya
2nd December 2015, 09:24
setting DESTDIR and running qmake changes the working directory that you have been doing manually so far.. That should open up several ways to tackle up your problem..

anda_skoa
4th December 2015, 15:34
The working directory is what the program runs in, not necessarily where it is installed to.

E.g. when you launch a program from a shell, the current directory in the shell is usually used as the working directory of the launched program.
When a program is launched via other means, that will usually lead to a different working directory, e.g. the user's home directory.

However, the working directory is highly irrelevant when it comes to library lookup.
That the program works if the working directory points to the directory with the DLLs is nothing to rely on.

DLLs that are loaded by the system library loader (as opposed to plugins) need to be in the search paths used by the system library loader.
On Windows that are the application install directory and some system directories.

Cheers,
_