Results 1 to 3 of 3

Thread: remember file path

  1. #1
    Join Date
    Nov 2007
    Posts
    57
    Thanks
    36
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default remember file path

    Hi all,

    I am using the below code to obtain filenames from the folder. Everything is working fine but I don't want to be taken back to the same folder every time I execute the code. Instead I want the program to remember what folder was last opened by the user and I want the program to offer that folder as the default. In other words, I want the current folder to change as the new folder is opened by the user. I know there is "setCurrent()" that I could perhaps use but I never got it working. Would anyone be able to help me with this code. Thanks a lot!

    Qt Code:
    1. QString filenametext = QFileDialog::getOpenFileName(this,
    2. tr("Open file"), QDir::current().dirName(),
    3. tr("Image Files (*.jpg *.jpeg)"));
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: remember file path

    You need to save that information somewhere dont u ??
    Once an application has stopped running u wont be able to retreive the information without saving it to the disk, isnt it ??

    so just save the info in some file or registry... and load it from there next time the application starts

  3. The following user says thank you to aamer4yu for this useful post:

    eric (1st April 2008)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: remember file path

    I use a following snippet:

    Qt Code:
    1. QDir lastDir = QDir::current();
    2. QString file = QFileDialog::getOpenFileName(this, "xx", lastDir.absolutePath());
    3. if(!file.isEmpty()){
    4. lastDir = QFileInfo(file).absoluteDir();
    5. }
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to wysota for this useful post:

    eric (1st April 2008)

Similar Threads

  1. Problem to find file path
    By phillip_Qt in forum Qt Programming
    Replies: 14
    Last Post: 28th April 2008, 10:06
  2. Set up the Qt4.3.2 with Visual Studio 2005
    By lamoda in forum Installation and Deployment
    Replies: 6
    Last Post: 30th January 2008, 06:51
  3. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21
  4. getting absolute file path of Qt resources
    By dvmorris in forum Qt Programming
    Replies: 6
    Last Post: 18th April 2007, 02:56
  5. qtreeview -file path
    By onder in forum Newbie
    Replies: 3
    Last Post: 12th July 2006, 09:40

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.