Remove current directory from selectedFolder
-
Hello,
I use a FolderDialog to choose a directory.
On return I would like to have only the path of the directory relative to the folder specified in input.how to remove the shortcuts.home contained in the returned URL
FolderDialog { id: folderDialog currentFolder: shortcuts.home onAccepted: { console.log("non : " + selectedFolder) }
in my case :
shortcuts.home = "file:///Volumes/Externe/Dev/Qt6/QtQuick/AIMLog_2/"selectedFolder = "file:///Volumes/Externe/Dev/Qt6/QtQuick/AIMLog_2/icons"
I want only "./icons"
-
@GrecKo
I'm sorry but when I add StandardPaths
i have the message : StandardPaths is not defined
Which module should be imported ?@JM-baubet that can be easily found in the Qt Creator help or google but here it is: the module you need to import is QtCore.
Note that you need to look at the doc ofStandardPaths
to know how to use it, in order to port fromshortcuts
. -
Hello,
I use a FolderDialog to choose a directory.
On return I would like to have only the path of the directory relative to the folder specified in input.how to remove the shortcuts.home contained in the returned URL
FolderDialog { id: folderDialog currentFolder: shortcuts.home onAccepted: { console.log("non : " + selectedFolder) }
in my case :
shortcuts.home = "file:///Volumes/Externe/Dev/Qt6/QtQuick/AIMLog_2/"selectedFolder = "file:///Volumes/Externe/Dev/Qt6/QtQuick/AIMLog_2/icons"
I want only "./icons"
@JM-baubet
I don't know about QML but you are in JavaScript here, right? So that has https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace, something like:folder = selectedFolder.replace(shortcuts.home, "")
-
@JM-baubet
I don't know about QML but you are in JavaScript here, right? So that has https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace, something like:folder = selectedFolder.replace(shortcuts.home, "")
-
@JonB I try this :
FolderDialog { id: folderDialog currentFolder: shortcuts.home onAccepted: { console.log("non : " + selectedFolder.replace(shortcuts.home, "") }
but I have an error : ReferenceError: shortcuts is not defined
@JM-baubet
shortcuts
is not usable in FolderDialog. UseStandardPaths
instead. -
@JonB I try this :
FolderDialog { id: folderDialog currentFolder: shortcuts.home onAccepted: { console.log("non : " + selectedFolder.replace(shortcuts.home, "") }
but I have an error : ReferenceError: shortcuts is not defined
@JM-baubet said in Remove current directory from selectedFolder:
but I have an error : ReferenceError: shortcuts is not defined
Like I said, I don't know QML, maybe you have to use
currentFolder
?
I think that is a separate issue from what @GrecKo has said about what to setcurrentFolder
to. -
@JM-baubet
shortcuts
is not usable in FolderDialog. UseStandardPaths
instead. -
@GrecKo
I'm sorry but when I add StandardPaths
i have the message : StandardPaths is not defined
Which module should be imported ?@JM-baubet that can be easily found in the Qt Creator help or google but here it is: the module you need to import is QtCore.
Note that you need to look at the doc ofStandardPaths
to know how to use it, in order to port fromshortcuts
. -
@GrecKo
I'm sorry but when I add StandardPaths
i have the message : StandardPaths is not defined
Which module should be imported ?@JM-baubet
Qt5: import Qt.labs.platform 1.1
Qt6: import Qt.labs.platform -
Thank you for your help
import QtCore ... FolderDialog { id: folderDialog selectedFolder.toString().replace(Qt.resolvedUrl("./../.."), "") alertEvenement.opacity = 0 // Il faut enregistrer le setting dnas le fichier python console.log("./" + selectedFolder.toString().replace(Qt.resolvedUrl("./../.."), "")) } }
-
J JM baubet has marked this topic as solved on