Results 1 to 2 of 2

Thread: Problems with the current working directory.

  1. #1
    Join Date
    Jun 2008
    Posts
    83
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Problems with the current working directory.

    I'm writing a program using QtCreator that uses some files in a folder (data) in the same folder as the project folder. I'm working under linux.

    In the constructor I have a line that is QFile file("./data/file.ext"). When I execute the program in the creator everything is fine.

    However it fails when I launch it by double clicking the created executable because the the program thinks that it is in /home/user/Documents. (I checked by having a button that creates a message with the output of QDir::current().absoulutePath().

    My question is why? and how can I change the working folder to the folder where the program executes?

    Thank you very much for any input.

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problems with the current working directory.

    The current directory can be anything upon startup, but you can always find the path to your applications executable via argv[0]

    Your shell most likely sets the cwd to /home/user/Documents so that directory is shown by default for any file saving/loading (a sensible decision - users will not want to manually select it everytime to save there work)

Similar Threads

  1. Replies: 3
    Last Post: 5th January 2009, 21:55
  2. Getting Current Directory.
    By afflictedd2 in forum Qt Programming
    Replies: 2
    Last Post: 16th November 2008, 22:27
  3. Qt 4 current directory path
    By bunjee in forum Qt Programming
    Replies: 1
    Last Post: 7th May 2008, 18:58
  4. Couldn't change current directory in windows's QT
    By sinha.ashish in forum Qt Programming
    Replies: 3
    Last Post: 25th February 2008, 05:00
  5. setting working directory for current process
    By mule in forum Qt Programming
    Replies: 1
    Last Post: 8th October 2007, 13:54

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.