Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Remove current directory from selectedFolder
Forum Updated to NodeBB v4.3 + New Features

Remove current directory from selectedFolder

Scheduled Pinned Locked Moved Solved QML and Qt Quick
9 Posts 4 Posters 685 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • JM baubetJ Offline
    JM baubetJ Offline
    JM baubet
    wrote on last edited by
    #1

    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"

    JonBJ 1 Reply Last reply
    0
    • JM baubetJ JM baubet

      @GrecKo
      I'm sorry but when I add StandardPaths
      i have the message : StandardPaths is not defined
      Which module should be imported ?

      GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #7

      @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 of StandardPaths to know how to use it, in order to port from shortcuts.

      1 Reply Last reply
      0
      • JM baubetJ JM baubet

        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"

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #2

        @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 baubetJ 1 Reply Last reply
        0
        • JonBJ JonB

          @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 baubetJ Offline
          JM baubetJ Offline
          JM baubet
          wrote on last edited by
          #3

          @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

          GrecKoG JonBJ 2 Replies Last reply
          0
          • JM baubetJ JM baubet

            @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

            GrecKoG Offline
            GrecKoG Offline
            GrecKo
            Qt Champions 2018
            wrote on last edited by
            #4

            @JM-baubet shortcuts is not usable in FolderDialog. Use StandardPaths instead.

            JM baubetJ 1 Reply Last reply
            1
            • JM baubetJ JM baubet

              @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

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #5

              @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 set currentFolder to.

              1 Reply Last reply
              0
              • GrecKoG GrecKo

                @JM-baubet shortcuts is not usable in FolderDialog. Use StandardPaths instead.

                JM baubetJ Offline
                JM baubetJ Offline
                JM baubet
                wrote on last edited by
                #6

                @GrecKo
                I'm sorry but when I add StandardPaths
                i have the message : StandardPaths is not defined
                Which module should be imported ?

                GrecKoG JoeCFDJ 2 Replies Last reply
                0
                • JM baubetJ JM baubet

                  @GrecKo
                  I'm sorry but when I add StandardPaths
                  i have the message : StandardPaths is not defined
                  Which module should be imported ?

                  GrecKoG Offline
                  GrecKoG Offline
                  GrecKo
                  Qt Champions 2018
                  wrote on last edited by
                  #7

                  @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 of StandardPaths to know how to use it, in order to port from shortcuts.

                  1 Reply Last reply
                  0
                  • JM baubetJ JM baubet

                    @GrecKo
                    I'm sorry but when I add StandardPaths
                    i have the message : StandardPaths is not defined
                    Which module should be imported ?

                    JoeCFDJ Offline
                    JoeCFDJ Offline
                    JoeCFD
                    wrote on last edited by
                    #8

                    @JM-baubet
                    Qt5: import Qt.labs.platform 1.1
                    Qt6: import Qt.labs.platform

                    1 Reply Last reply
                    0
                    • JM baubetJ Offline
                      JM baubetJ Offline
                      JM baubet
                      wrote on last edited by
                      #9

                      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("./../.."), ""))
                              }
                          }
                      
                      
                      1 Reply Last reply
                      0
                      • JM baubetJ JM baubet has marked this topic as solved on

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved