Search code examples
qtqmlqtquick2qtquickcontrolsqtwidgets

Setting default starting directory for FileDialog


I am trying to set a default starting directory for FileDialog in QtQuick, but it does not work (meaning it always opens the executable's directory) :

property url defPath : "/home/saeid/Work/data";

FileDialog {
    id:dialogPosPath;
    selectFolder: true;
    title: "Please select folder";
    folder: defPath;
    //rest of stuff

But if I set the folder property to e.g. folder:shortcuts.home it works fine! I don't understand why.

The documentation says:

The path to the currently selected folder. Setting this property before invoking open() will cause the file browser to be initially positioned on the specified folder.

The value of this property is also updated after the dialog is closed.

By default, the url is empty.

Any idea how to implement this?


Solution

  • You should use the file scheme:

    "file:///home/saeid/work/data"