简体   繁体   English

QFileDialog(QT 5.2.1 / mingw32)不允许我选择只读文件

[英]QFileDialog (QT 5.2.1/mingw32) won't allow me to choose a read-only file

QT 5.2.1 QT 5.2.1
Win7 64-bit Win7 64位

I'm using QFileDialog to choose a filename 我正在使用QFileDialog选择文件名

  • it's unknown at time of choosing whether the file will be written or read, so QFileDialog::getOpenFilename() and QFileDIalog::getSaveFilename() don't work well for this. 在选择是写入文件还是读取文件时尚不清楚,因此QFileDialog :: getOpenFilename()和QFileDIalog :: getSaveFilename()不适用于此情况。

For some reason, I can't choose a file that's marked "read-only". 由于某些原因,我无法选择标记为“只读”的文件。

If I pass the option for "DontUseNativeDialog", then I can select a read-only file. 如果我通过“ DontUseNativeDialog”选项,则可以选择一个只读文件。 However, that is less than ideal. 但是,这并不理想。 AFAICT, there's no reason that I shouldn't be able to choose a read-only file with the native dialog. AFAICT,没有理由我不能使用本机对话框选择只读文件。 Is this just a bug in the windows implementation, or am I missing something? 这仅仅是Windows实现中的错误,还是我缺少了什么?

Relevant code for creating the dialog: 创建对话框的相关代码:

// create a generic FileDialog
QFileDialog dialog(NULL, tr("Select a disk image"));
dialog.setNameFilter(tr("Image Files (*.img *.IMG);;*.*"));
dialog.setFileMode(QFileDialog::AnyFile);  // should be default
dialog.setViewMode(QFileDialog::Detail);   // should be default
dialog.setAcceptMode(QFileDialog::AcceptOpen);  // should be default
dialog.setOption(QFileDialog::DontConfirmOverwrite, true);

QString fileLocation = NULL;
if (dialog.exec())
{
    // selectedFiles returns a QStringList - only expecting 1 filename,
    //      so use the zero'th element from that list
    fileLocation = (dialog.selectedFiles())[0];
}

Complete test project is pasted here: 完整的测试项目粘贴在这里:
http://pastebin.com/TuM4AY4x http://pastebin.com/TuM4AY4x

It's a bug in QT5.2.1. 这是QT5.2.1中的错误。 It's supposedly fixed in 5.3 alpha. 它应该在5.3 alpha中修复。
https://bugreports.qt-project.org/browse/QTBUG-36886 https://bugreports.qt-project.org/browse/QTBUG-36886

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM