PDA

View Full Version : remember file path



eric
1st April 2008, 16:41
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!



QString filenametext = QFileDialog::getOpenFileName(this,
tr("Open file"), QDir::current().dirName(),
tr("Image Files (*.jpg *.jpeg)"));

aamer4yu
1st April 2008, 17:14
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

wysota
1st April 2008, 17:52
I use a following snippet:


QDir lastDir = QDir::current();
QString file = QFileDialog::getOpenFileName(this, "xx", lastDir.absolutePath());
if(!file.isEmpty()){
lastDir = QFileInfo(file).absoluteDir();
}