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. FileDialog setting initial directory

FileDialog setting initial directory

Scheduled Pinned Locked Moved Solved QML and Qt Quick
10 Posts 2 Posters 2.9k 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.
  • F Offline
    F Offline
    fcarney
    wrote on 10 Jan 2019, 19:06 last edited by fcarney 1 Oct 2019, 19:07
    #1

    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-prop

    What kind of url/path does folder need?

    C++ is a perfectly valid school of magic.

    1 Reply Last reply
    1
    • F Offline
      F Offline
      fcarney
      wrote on 10 Jan 2019, 19:21 last edited by
      #2

      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.)
      

      C++ is a perfectly valid school of magic.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fcarney
        wrote on 10 Jan 2019, 19:31 last edited by
        #3

        Now I am really confused:

        saveDialog.folder  =  "file:///" + dir
        

        Apparently it needs 3 slashes.

        C++ is a perfectly valid school of magic.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 10 Jan 2019, 19:33 last edited by
          #4

          Hi,

          IIRC: file:// is the protocol and the third slash is the start of your path.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • F Offline
            F Offline
            fcarney
            wrote on 10 Jan 2019, 19:49 last edited by fcarney 1 Oct 2019, 19:50
            #5

            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.

            C++ is a perfectly valid school of magic.

            1 Reply Last reply
            0
            • F Offline
              F Offline
              fcarney
              wrote on 10 Jan 2019, 20:08 last edited by
              #6

              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?

              C++ is a perfectly valid school of magic.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 10 Jan 2019, 20:32 last edited by
                #7

                Ok, as you wish, I won't tell it. You can hack Qt's sources if you prefer.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  fcarney
                  wrote on 10 Jan 2019, 20:54 last edited by
                  #8

                  Ouch! Thanks for the confirmation. I know sometimes its hard to be the messenger. Thanks again.

                  C++ is a perfectly valid school of magic.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 10 Jan 2019, 21:13 last edited by
                    #9

                    By the way, where do you get dir from ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • F Offline
                      F Offline
                      fcarney
                      wrote on 10 Jan 2019, 21:36 last edited by
                      #10

                      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.

                      C++ is a perfectly valid school of magic.

                      1 Reply Last reply
                      0

                      5/10

                      10 Jan 2019, 19:49

                      • Login

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