QFileDialog::getOpenFileName can't jump to the right directory on mac
-
Hi:
I developed a cross-platform qt app which works on both mac and windows, in my app, I want to get a file from my mac, so I use QFileDialog, here is my code:QString qstr_path = QFileDialog::getOpenFileName(this, tr("Open Project"), projdir_qstr, "allfiles(*.bundle)");
int the mac which macosx is 10.14,and the projdir_qstr = /Users/lee/Library/Caches/FUCreator/Projects/,it work very fine,can show me the 'Projects' directory.
but the other mac which macosx is 10.13,and the projdir_qstr = /Users/FaceUnity/Library/Caches/FUCreator/Projects/,it can't open the 'Projects' directory,only shows me the 'Users' directory,here is the picture:
I don't know why, could you help me, thanks a lot!
-
Hi
Have you checked if the path is valid (all directories exist)?
In general it's better to use QStandardPath and then navigate through your project directory / AppDir, instead of hardcoding the whole path.
It ensures, that you start in that directory, where your program is executed (especially if you work with multiple systems / devices)
-
@jsulm yes, the /Users/FaceUnity/Library/Caches/FUCreator/Projects is a valid path!, I use the 'open' command can open the /Users/FaceUnity/Library/Caches/FUCreator/Projects directory,but use the QFileDialog::getOpenFileName can't open the 'Projects' and shows me the 'Users' directory!
-
@J.Hilk said in QFileDialog::getOpenFileName can't jump to the right directory on mac:
in
IIRC there was a problem with getOpenFileName in one of the 5.12 releases, but that clearly does not apply to your case...but, I certainly have this problem, what should I do? can you give me some suggestion!
-
@Princein
well get the source qt (QtBase- module) and inspect the QFileDialog class.Fix it and compile it.
You should check if your issue is still there with the latest QtVersion and if it's fixed there, you can simply compare the source code to find and fix the issue