Planned maintenance has been done but it did not solve the problem. So work will continue on this and a new time for trying updates will be announced asap.

Qt 4.7.3 - QFileDialog - Remember the last directory from one call to another



  • 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, I know how to do that, but only if the user selects at least one file. What I would like, now, 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. 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?



  • Not with the static functions. If you use the native dialog without the static functions you might be able to check the latest or current directory. I haven't checked that.



  • What do you mean by the native dialog? Do you mean creating an instance of QFileDialog and then calling exec()? If so, then I guess it might work if I was to handle the directoryEntered signal. However, if you are really talking about calling the exec() method, then the dialog box really doesn't look great at all and, on Windows 7 at least, really doesn't look native.



  • I meant the non-native dialog. Typo there. Yes it looks significantly different, but it will allow you achieve your goal. Another approach might be to spawn the native windows dialog yourself, but I don't know if that will help you in this matter.



  • Yes, I have been thinking about doing that, even though I am not very optimistic about that approach. Still, I shall give it a try tomorrow.



  • Ok, I have just had a look. QFileDialog::getOpenFileNames calls, on Windows, qt_win_get_open_file_names and well... it gets pretty messy from there, so it would seem to me that there is, unfortunately, no easy way to achieve what I am after. :(



  • Just a tip, but couldn't this be achived trough "saveState()":http://doc.qt.nokia.com/4.7/qfiledialog.html#saveState "QSettings":http://doc.qt.nokia.com/4.7/qsettings.html and "restoreState()":http://doc.qt.nokia.com/4.7/qfiledialog.html#restoreState something like "this":http://truth2.wordpress.com/2008/12/13/splitter-stretch-factor-widget-sizes/? (sorry, couldn't find a better example :))



  • Yes, I was aware of those methods and I guess that it should work (at least, based on the documentation), but unless I am mistaken this would involve creating an instance of QFileDialog and therefore using the exec() method which I am against (see above for the reason).


Log in to reply