From 928cab5ff1d931d00074d8930c41537109814371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Fri, 18 Jan 2019 15:02:32 +0100 Subject: wasm: add public API for local file access The web sandbox restricts access to the local file system, which means Qt needs new public API to provide such access to applications. This adds a new static, asynchornous getOpenFileContent() function to QFileDialog, which will show a file dialog, read the file contents once a file has been selected, and finally call the user-provided callback with the selected file name and file data. auto fileReady = [](const QString &fileName, const QByteArray &fileContents) { // Process file } QFileDialog::getOpenFileContent("*.*", fileReady); This API can be expanded in at least two ways in the future: allow reading multiple files, and allow file streaming by returning a QOIDevice. Change-Id: I011b92fbcf21f0696604e66b7f9eb265c1a07aaa Reviewed-by: Lorn Potter --- src/widgets/doc/snippets/code/src_gui_dialogs_qfiledialog.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/widgets/doc/snippets/code') diff --git a/src/widgets/doc/snippets/code/src_gui_dialogs_qfiledialog.cpp b/src/widgets/doc/snippets/code/src_gui_dialogs_qfiledialog.cpp index 06cca37111..1e9daf824b 100644 --- a/src/widgets/doc/snippets/code/src_gui_dialogs_qfiledialog.cpp +++ b/src/widgets/doc/snippets/code/src_gui_dialogs_qfiledialog.cpp @@ -144,3 +144,14 @@ dialog.exec(); //! [14] "Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)" //! [14] + +//! [14] +auto fileOpenCompleted = [](const QSting &fileName, const QByteArray &fileContent) { + if (fileName.isEmpty()) { + // No file was selected + } else { + // Use fileName and fileContent + } +} +QFileDialog::getOpenFileContent("Images (*.png *.xpm *.jpg)", fileContentReady); +//! [14] -- cgit v1.2.3