sazr
sazr

Reputation: 25928

QML Set FileDialog folder property to valid path but not adhered to

When my QML FIleDialog opens I want it to open in a specific directory. But it's not doing so. It always opens in the directory the .exe is executing from.

I have set the QML property folder to a valid directory but its not working. If I set folder to shortcuts.home it does work.

Can you provide advice on whats wrong?

FileDialog {
    id: fileDialog
    title: "Please choose a file"
    folder: "D:/_Work/foo/bar/" // Note shortcuts.home does work
    nameFilters: [ "Image files (*.jpg *.png)", "All files (*)" ]
    onAccepted: {
        image.source = fileDialog.fileUrl
    }
    onRejected: {
        console.log("Canceled")
    }
}

Upvotes: 2

Views: 2005

Answers (1)

talamaki
talamaki

Reputation: 5472

Type of the FileDialog folder property is url. Now you are binding a local file path to that property. You can make a local file path a url by adding file:/// (Windows) or file:// (Linux/Mac) in front of the file path.

Note: shortcuts.home will provide the url of the user's home directory.

Upvotes: 1

Related Questions