Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Solved FileDialog choosing save directory

    QML and Qt Quick
    3
    12
    2006
    Loading More Posts
    • 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.
    • Yunus
      Yunus last edited by

      hi, I want to create a text file and I want to save it to a chosen directory via on qml. Is there a simple way to do that with FileDialog.

      JonB 1 Reply Last reply Reply Quote 0
      • JonB
        JonB @Yunus last edited by

        @Yunus
        Did you read the docs https://doc.qt.io/qt-5/qml-qtquick-dialogs-filedialog.html#folder-prop ?

        1 Reply Last reply Reply Quote 2
        • Yunus
          Yunus last edited by

          @JonB yeah I did. but I couldnt find a solution there. All I need is choosing a directory for my file using filediaolg

          JonB 1 Reply Last reply Reply Quote 0
          • JonB
            JonB @Yunus last edited by

            @Yunus
            Then I don't understand your question.

            hi, I want to create a text file and I want to save it to a chosen directory via on qml. Is there a simple way to do that with FileDialog

            Setting folder: ... sets the initial folder of your save file dialog. What is it that you want if not that?

            1 Reply Last reply Reply Quote 1
            • Yunus
              Yunus last edited by

              @JonB

              FileDialog {
              id: fileDialog
              title: "Please choose a file"
              folder: shortcuts.home
              onAccepted: {
              console.log("You chose: " + fileDialog.fileUrls)
              controller.savetmp(fileDialog.fileUrl.toString());
              }
              onRejected: {
              console.log("Canceled")
              }
              }
              

              with this code piece I can choose my text file from any folder but I need to choose a directory to save it with the same way. Can you give me a simple example how to do that?

              JonB J.Hilk 2 Replies Last reply Reply Quote 0
              • JonB
                JonB @Yunus last edited by JonB

                @Yunus
                Sorry, I may be being dumb (and I don't use QML!), but I still don't get what you asking for! The user can already change the directory in this dialog, so the user can navigate off to anywhere desired, right? Meanwhile, for saving to a new file if that is what you want, have you looked at https://doc.qt.io/qt-5/qml-qtquick-dialogs-filedialog.html#selectExisting-prop and/or https://doc.qt.io/qt-5/qml-qtquick-dialogs-filedialog.html#selectFolder-prop, you may want to set either of these true for what you're asking, I am unsure (e.g. if you mean you only want the user to choose a directory/folder and not the filename you need selectFolder: true?)

                1 Reply Last reply Reply Quote 1
                • J.Hilk
                  J.Hilk Moderators @Yunus last edited by

                  @Yunus
                  to set your FileDialog to folder mode use the following property:
                  selectFolder: true

                  //untested
                  FileDialog {
                   id: fileDialog
                   title: "Please choose a folder"
                   folder: shortcuts.home
                  selectMultiple: false
                  selectExisting: true
                  selectFolder: true
                   onAccepted: {
                   console.log("You chose: " + fileDialog.fileUrls)
                  
                   }
                   onRejected: {
                   console.log("Canceled")
                   }
                   }
                  

                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct

                  Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  Yunus 1 Reply Last reply Reply Quote 2
                  • Yunus
                    Yunus last edited by

                    @JonB I fixed it ty bro. I just missed a point. Now I can choose my directory. But now another problem, while choosing my directory, how can I name my folder on the same window? Is there a way to do that? Thank you so much again

                    JonB 1 Reply Last reply Reply Quote 0
                    • Yunus
                      Yunus @J.Hilk last edited by

                      @J.Hilk Thank you.

                      1 Reply Last reply Reply Quote 0
                      • JonB
                        JonB @Yunus last edited by JonB

                        @Yunus

                        But now another problem, while choosing my directory, how can I name my folder on the same window?

                        I seem to have problems understanding your questions! :) If you're choosing a directory, what are trying to name? Anyway all I can think you might mean is selectExisting: false:

                        Setting this property to false implies that the dialog is for naming a file to which to save something, or naming a folder to be created;

                        though selectFolder says

                        Setting this property to true implies that [...] selectExisting must be true.

                        so I'm not sure what you need to have if you want to "naming a folder to be created", you'll have to try.

                        1 Reply Last reply Reply Quote 0
                        • Yunus
                          Yunus last edited by

                          @JonB What a bad thing not to understand each other :) Now, I chose a directory(a folder which have no extension). And I will save my text file to this directory. But I want to give name my text file while choosing its directory. This procedure is same for all saving steps. I hope I m clear :((

                          JonB 1 Reply Last reply Reply Quote 0
                          • JonB
                            JonB @Yunus last edited by JonB

                            @Yunus
                            But that's right what we started out with!? To pick a file you want selectFolder: false, and to pick a new file to save you want selectExisting: false.

                            Maybe you mean you want the user to be able to create a new folder at the same time as creating a new file in it? Well, I haven't seen the dialog, but if it's like in Qt/native Windows you can usually do some kind of right-click while you're in the dialog (or maybe there is some button for this) which lets user create a sub-directory before then choosing the final filename?

                            1 Reply Last reply Reply Quote 1
                            • First post
                              Last post