简体   繁体   中英

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

QT 5.2.1
Win7 64-bit

I'm using QFileDialog to choose a filename

  • 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.

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. 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. Is this just a bug in the windows implementation, or am I missing something?

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

It's a bug in QT5.2.1. It's supposedly fixed in 5.3 alpha.
https://bugreports.qt-project.org/browse/QTBUG-36886

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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