I have a Windows application based on Qt WebEngineView (in QML). There are web pages in my app. Some web page need user to select files using:
<input type="file" />
I want to know, is it possible for my app to remember the last directory user selected a file?
I have tried:
<input>
in my web page, but it is not allowed by browser to set it programmatically, see Set default value for a input file form.I know this may be impossible. Any suggestions and workarounds are appreciated.
The WebEngineView
element has a signal for when the Web content requests a file dialog.
The FileDialog
element has a property for setting (and getting) the folder.
So something along these lines should work
FileDialog {
id: dialog
property var request
onRejected: request.dialogReject()
onAccepted: {
yourSavedFolder = folder;
request.dialogAccept(files);
}
}
WebEngineView {
onFileDialogRequested: {
request.accepted = true; // inhibit default dialog
dialog.request = request;
dialog.folder = yourSavedFolder;
dialog.open()
}
}
This is just a rough sketch, you'll also need to handle the open mode of the request object, etc.