PDA

View Full Version : Qt 4.7.3 - QFileDialog - Remember the last directory from one call to another



agarny
6th May 2011, 20:06
I am using QFileDialog::getOpenFileNames to open one or several files in my application and that works fine.

However, I would like to remember the last used directory from one call to another. Now, yes, I am aware that this has already been discussed before (e.g. here (http://www.qtcentre.org/threads/41281-Making-filedialog-remember-previous-directory) and here (http://www.qtcentre.org/threads/9597-QFileDialog-getOpenFileName-and-the-last-used-directory)), but that's what I already have in my application and isn't quite what I am after.

Indeed, the above works fine, but only if the user selects at least one file. What I would like is to be able to handle the case where the user ends in a directory (which is different from the starting one) and closes the dialog box without having selected any file. Now, even though no file has been selected, it would still be nice to keep track of that directory. However, it seems to me like it might not be possible or is it?

ars
6th May 2011, 22:21
If you use a QFileDialog object instead of the static method, you can use QFileDialog::directory() method to query the recently active directory when exec() terminates.
Maybe that's an option for you.

agarny
6th May 2011, 23:32
If you use a QFileDialog object instead of the static method, you can use QFileDialog::directory() method to query the recently active directory when exec() terminates.
Maybe that's an option for you.Yes, sorry, I guess I should have mentioned that the exec() method is out of question for me, since the file dialog box that it uses really doesn't look native at all (at least, on Windows 7; I haven't tried on Linux and Mac OS X).