QFileDialog: Improve default implementation of getOpenFileContent()
Use QFileDialog::ExistingFile and check whether file can be opened, fixing warnings like: QIODevice::read (QFile, "/home/.../blub"): device not open Change-Id: I7ee1d59f01383c581bc09fb44855835aae8c246b Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
parent
5f940253bf
commit
2c390e85cf
@ -2438,14 +2438,15 @@ void QFileDialog::getOpenFileContent(const QString &nameFilter, const std::funct
|
||||
(*openFileImpl)();
|
||||
#else
|
||||
QFileDialog *dialog = new QFileDialog();
|
||||
dialog->setFileMode(QFileDialog::ExistingFile);
|
||||
dialog->selectNameFilter(nameFilter);
|
||||
|
||||
auto fileSelected = [=](const QString &fileName) {
|
||||
QByteArray fileContent;
|
||||
if (!fileName.isNull()) {
|
||||
QFile selectedFile(fileName);
|
||||
selectedFile.open(QIODevice::ReadOnly);
|
||||
fileContent = selectedFile.readAll();
|
||||
if (selectedFile.open(QIODevice::ReadOnly))
|
||||
fileContent = selectedFile.readAll();
|
||||
}
|
||||
fileOpenCompleted(fileName, fileContent);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user