FileDialog choosing save directory



  • 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 yeah I did. but I couldnt find a solution there. All I need is choosing a directory for my file using filediaolg



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



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



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


  • Moderators

    @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")
     }
     }
    


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



  • @J.Hilk Thank you.



  • @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.



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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.