summaryrefslogtreecommitdiffstats
path: root/src/widgets/doc/snippets/code
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@qt.io>2019-01-18 15:02:32 +0100
committerMorten Johan Sørvig <morten.sorvig@qt.io>2019-02-07 06:49:31 +0000
commit928cab5ff1d931d00074d8930c41537109814371 (patch)
tree2e242d8143e4b975d1a22aa650de0060189db4bd /src/widgets/doc/snippets/code
parent790cf25f9d811f2cda7e252b4f1844e8fce27e2a (diff)
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 <lorn.potter@gmail.com>
Diffstat (limited to 'src/widgets/doc/snippets/code')
-rw-r--r--src/widgets/doc/snippets/code/src_gui_dialogs_qfiledialog.cpp11
1 files changed, 11 insertions, 0 deletions
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]