[英]QFileDialog::getOpenFileName doesn't set the initial directory on Mac OS 10.8 Mountain Lion
I can not change the current directory with QFileDialog with Qt 4.8.我无法使用 Qt 4.8 使用 QFileDialog 更改当前目录。 The same code works fine on Windows and Mac OS 10.6 Snow Leopard.
相同的代码在 Windows 和 Mac OS 10.6 Snow Leopard 上运行良好。 It also works fine if I don't use the native Mac OS X dialog.
如果我不使用本机 Mac OS X 对话框,它也可以正常工作。
This works:这有效:
fn=QFileDialog::getOpenFileName(this,"Select File","/Users/myuser/Desktop",QString(),0,QFileDialog::DontUseNativeDialog);
This doesn't work:这不起作用:
fn=QFileDialog::getOpenFileName(this,"Select File","/Users/myuser/Desktop");
It looks like if most of the time it opens the last path of the last call to getOpenFileName.看起来如果大多数时候它打开最后一次调用 getOpenFileName 的最后一个路径。
Got the same issue with Qt5.2.0 on Mavericks... I found a work around: append a dummy file name to the directory you want to select.在 Mavericks 上使用 Qt5.2.0 遇到了同样的问题......我找到了一个解决方法:将一个虚拟文件名附加到您要选择的目录中。 However, be sure not to do this on Windows because the user will see it.
但是,请确保不要在 Windows 上执行此操作,因为用户会看到它。
QString dir = "/Users/myuser/Desktop";
#if defined(__APPLE__)
dir += "/MyFile.txt";
#endif
fn = QFileDialog::getOpenFileName(this, "Select File", dir);
Also, for those like me that instantiate a file dialog because they need more options you can also do:此外,对于像我这样实例化文件对话框的人,因为他们需要更多选项,您还可以执行以下操作:
QFileDialog fileDialog(this, "Select File");
#if defined(__APPLE__)
fileDialog.selectFile(dir + "/MyFile.txt");
#else
fileDialog.setDirectory(dir);
#endif
...
This is a bug in Qt that is reportedly fixed in Qt 5.0.1 and Qt 4.8.4 (though it seems that it still reproducible in 4.8.4 by people (myself included)).这是 Qt 中的一个错误,据报道已在 Qt 5.0.1 和 Qt 4.8.4 中修复(尽管人们(包括我自己)似乎仍然可以在 4.8.4 中重现它)。
This bug has been reported in JIRA as QTBUG-20771 , QTBUG-28161 and finally QTBUG-35779 (which appears to have finally fully resolved the issue in Qt 5.2.1).这个错误在 JIRA 中被报告为QTBUG-20771 、 QTBUG-28161和最后的QTBUG-35779 (这似乎最终完全解决了 Qt 5.2.1 中的问题)。 Here is a link to the patch in Gerrit .
这是Gerrit 中补丁的链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.