FileDialog setting initial directory
-
wrote on 10 Jan 2019, 19:06 last edited by fcarney 1 Oct 2019, 19:07
I have a FileDialog defined like so:
FileDialog { id: saveDialog property Action fileSaveAction: Action{} onAccepted: { console.log("You chose: " + saveDialog.fileUrl) fileSaveAction.trigger() close() } onRejected: { console.log("Canceled") close() } }
I invoke it like this:
onSaveLocalFile:{ //url saveDialog.folder = "file://" + dir saveDialog.nameFilters = [ "Program files (*.xm)" ] saveDialog.title = "Save Weld Program As ,,," saveDialog.fileSaveAction = actionSavePrgm saveDialog.open() }
However, my "dir" is given to me as a native path. This method of setting folder fails with:
shellItem: SHCreateItemFromParsingName(file:///c)) failed (The operation completed successfully.)
I tried this:
saveDialog.folder = dir
I don't get an error, but it does not set the default directory correctly. It just goes to the local directory of where the program is running from. The directory should be going to:
C:\ProgramData\XM Editor\RnD\programs
The description of the property "folder" is as follows:
http://doc.qt.io/qt-5/qml-qtquick-dialogs-filedialog.html#folder-propWhat kind of url/path does folder need?
-
wrote on 10 Jan 2019, 19:21 last edited by
I managed to use QDir to convert my path into one that uses "/":
C:/ProgramData/XM Editor/RnD/programs
Now when trying to set that folder property I get this error:
shellItem: SHCreateItemFromParsingName(file:///c/ProgramData/XM Editor/RnD/programs)) failed (An attempt was made to reference a token that does not exist.)
-
wrote on 10 Jan 2019, 19:31 last edited by
Now I am really confused:
saveDialog.folder = "file:///" + dir
Apparently it needs 3 slashes.
-
Hi,
IIRC:
file://
is the protocol and the third slash is the start of your path. -
wrote on 10 Jan 2019, 19:49 last edited by fcarney 1 Oct 2019, 19:50
Does this mean I have to special case the Windows path? In Linux our paths generally come with "/" at the beginning because we use absolute paths. Is there a way to get a Windows path that has this "/" already? I tried using QDir to spit out a path, but it does not add the "/" at the beginning.
-
wrote on 10 Jan 2019, 20:08 last edited by
Hmmm, the more I dig into FileDialog the more I am really confused. Apparently it cannot be used as a "SaveAs" dialog. Then I looked for a Save/SaveAs dialog solution and find there is not such a thing in QtQuick/QML.
I then found this article. Please tell me I don't need to use private headers to create a QtQuick dialog to do Save/SaveAs functionality natively in QtQuick app. Please?
-
Ok, as you wish, I won't tell it. You can hack Qt's sources if you prefer.
-
wrote on 10 Jan 2019, 20:54 last edited by
Ouch! Thanks for the confirmation. I know sometimes its hard to be the messenger. Thanks again.
-
By the way, where do you get dir from ?
-
wrote on 10 Jan 2019, 21:36 last edited by
We have an existing class with methods that spit out the directory. It provides this dir for a lot of different places in the code. I found that the "folder" property would accept the native formatting as long as there are 3 "/" before it. So the formatting of the path was less important than the "/"s.
3/10