[SOLVED] QFileDialog no longer remembers directory between runs
-
I'm developing with Qt/MinGW on Windows 8.
It seems that the behavior of QFileDialog changed somewhere between Qt 5.1.1 and Qt 5.3.1 when creating an instance of QFileDialog (my instance is called fileDialog) and simply using:
@QStringList fileNames = fileDialog.getOpenFileNames(this, "Select File(s)", "",
"Images (" + imageWildcardString() + ")");@The same app compiled with 5.1.1 remembered the last directory used between runs (even when not run from within Qt Creator). It wasn't necessary to save any settings to get this behavior. The one compiled with Qt 5.3 doesn't. The directory changes are still remembered though for an instance of QDialog used multiple times within a single app run.
I think the problem may be related to QDialog::directory() that doesn't seem to have changed after I browsed somewhere with the dialog (even if I finally press OK and not Cancel). It seems to be stuck at the working directory.
Any bug confirmation or workaround would be greatly appreciated.
Eon
-
Might want to utilize the QSettings and at startup load the last used directory. If valid, change the current working directory of the application. That should do the trick.
-
[quote author="Jeroentje@home" date="1405073985"]Might want to utilize the QSettings and at startup load the last used directory. If valid, change the current working directory of the application. That should do the trick.[/quote]
That's exactly what I tried to do when I noticed that fileDialog.directory() also doesn't update when I browse to a directory. So I can't obtain the last used directory.
-
OK so I realize now that getOpenFileNames() is a static function and so of course fileDialog.directory() wouldn't be updated. I guess I've been using it wrong.
I think the specific behavior related to passing "" as the default dir is what changed.
What I'm going to do for a workaround is just use the path from the first selected file name returned as the path to save using QSettings.
Edit: The above workaround works.
Now how do I mark this tread as resolved?
-
Below your avatar there is an 'edit' link. Do this at your first post and place the [SOLVED] before the header ;-)
Greetz -
[quote author="Jeroentje@home" date="1405084930"]Below your avatar there is an 'edit' link. Do this at your first post and place the [SOLVED] before the header ;-)
Greetz[/quote]Thanks :)