Results 1 to 7 of 7

Thread: How to change working directory

  1. #1
    Join Date
    Nov 2015
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows

    Question How to change working directory

    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

  2. #2
    Join Date
    May 2015
    Posts
    66
    Thanks
    10
    Thanked 17 Times in 17 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to change working directory

    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/..

  3. #3
    Join Date
    Nov 2015
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to change working directory

    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.

  4. #4
    Join Date
    May 2015
    Posts
    66
    Thanks
    10
    Thanked 17 Times in 17 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to change working directory

    Ahh ok, you need DESTDIR variable in the pro file to point to a specific folder always. Example:

    Qt Code:
    1. DESTDIR = $$PWD/../../Runtime/Bin
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Nov 2015
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to change working directory

    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

  6. #6
    Join Date
    May 2015
    Posts
    66
    Thanks
    10
    Thanked 17 Times in 17 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to change working directory

    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..

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to change working directory

    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,
    _

Similar Threads

  1. Cannot change to working directory
    By knobby67 in forum Newbie
    Replies: 1
    Last Post: 26th August 2014, 21:50
  2. QProcess - Working directory problem
    By jomarin in forum Qt Programming
    Replies: 4
    Last Post: 27th November 2008, 16:26
  3. Set Working Directory in VS
    By Lele in forum Qt Programming
    Replies: 1
    Last Post: 20th February 2008, 17:03
  4. Don't want QTextBrowser to look in working directory
    By magland in forum Qt Programming
    Replies: 1
    Last Post: 20th October 2007, 23:14
  5. QT Service and working directory
    By Lele in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2006, 11:46

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.