简体   繁体   English

QFileDialog::getOpenFileName 不会在 Mac OS 10.8 Mountain Lion 上设置初始目录

[英]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-20771QTBUG-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.

相关问题 如何为Mac OS X 10.8 Mountain Lion设置Java JDK环境变量 - How to Set Java JDK Environment Variable for Mac OS X 10.8 Mountain Lion Mac OS X 10.8 Mountain Lion的内核调试工具包 - Kernel Debug Kit for Mac OS X 10.8 Mountain Lion 在Mac OS X 10.8 Mountain Lion上未调用该方法 - Method does not invoked on Mac OS X 10.8 Mountain Lion a2enmod不适用于Mac OS X - Mountain Lion - a2enmod doesn't work on Mac OS X - Mountain Lion 在 Mac OS 10.6 (Snow Leopard)、10.7 (Lion)、10.8 (Mountain Lion) 上激活 PHP 和 MySQL 的最简单方法? - Easiest way to activate PHP and MySQL on Mac OS 10.6 (Snow Leopard), 10.7 (Lion), 10.8 (Mountain Lion)? QFileDialog :: getOpenFileName在MAC 10.10.5优胜美地上不起作用 - QFileDialog::getOpenFileName doesn't working on MAC 10.10.5 Yosemite 为什么OCaml二进制文件在Mac OS X 10.8(Mountain Lion)上崩溃? - Why do OCaml binaries crash on Mac OS X 10.8 (Mountain Lion)? Mac OS X 10.8 Mountain Lion上安装了Oracle(Sun)的JDK / JRE在哪里? - Where is Oracle's (Sun's) JDK/JRE installed on Mac OS X 10.8 Mountain Lion? 如何在 Mac Mountain Lion OS X v10.8 上使用 pip 安装 Scipy - How to install Scipy with pip on Mac Mountain Lion OS X v10.8 如何在Mac OS X 10.8(山狮)中更改Homebrew的git origin远程位置? - How do I change the git origin remote location of Homebrew in Mac OS X 10.8 (mountain lion)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM