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 choosing save directory
QtWS25 Last Chance

FileDialog choosing save directory

Scheduled Pinned Locked Moved Solved QML and Qt Quick
12 Posts 3 Posters 3.4k 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.
  • YunusY Offline
    YunusY Offline
    Yunus
    wrote on last edited by
    #1

    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.

    JonBJ 1 Reply Last reply
    0
    • YunusY Yunus

      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.

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

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

      1 Reply Last reply
      2
      • YunusY Offline
        YunusY Offline
        Yunus
        wrote on last edited by
        #3

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

        JonBJ 1 Reply Last reply
        0
        • YunusY Yunus

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

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

          @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
          1
          • YunusY Offline
            YunusY Offline
            Yunus
            wrote on last edited by
            #5

            @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?

            JonBJ J.HilkJ 2 Replies Last reply
            0
            • YunusY Yunus

              @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?

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

              @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
              1
              • YunusY Yunus

                @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?

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #7

                @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


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

                YunusY 1 Reply Last reply
                2
                • YunusY Offline
                  YunusY Offline
                  Yunus
                  wrote on last edited by
                  #8

                  @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

                  JonBJ 1 Reply Last reply
                  0
                  • J.HilkJ J.Hilk

                    @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")
                     }
                     }
                    
                    YunusY Offline
                    YunusY Offline
                    Yunus
                    wrote on last edited by
                    #9

                    @J.Hilk Thank you.

                    1 Reply Last reply
                    0
                    • YunusY Yunus

                      @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

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

                      @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
                      0
                      • YunusY Offline
                        YunusY Offline
                        Yunus
                        wrote on last edited by
                        #11

                        @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 :((

                        JonBJ 1 Reply Last reply
                        0
                        • YunusY Yunus

                          @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 :((

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

                          @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
                          1

                          • Login

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