Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Open specific Folder in FileDialog



  • Hello,

    I am a beginner in QML/QT. I have the following problem:

    I want to open a specific folder in FileDialog on Android

    import QtQuick 2.9
    import QtQuick.Controls 2.5
    import QtQuick.Dialogs 1.3
    
    
    ApplicationWindow {
        width: 640
        height: 480
        visible: true
        title: qsTr("Hello World")
    
        menuBar: MenuBar{
            id: menuBar
            visible: GlobalDefinitions.isEditMode
    
            Menu{
                title: qsTr("&File")
    
                MenuItem{
                    text: qsTr("&Open File")
                    onTriggered: {
                        layoutLoadDialog.open()
                    }
                    FileDialog{
    
                        id: layoutLoadDialog
                        title: qsTr("Open Layout File")
                        selectExisting: true
                        sidebarVisible: false
                        folder: shortcuts.pictures
                        onAccepted: {
                           console.log("Accepted")
                        }
                    }
    
                }
            }
        }
    
    }
    

    The problem is that setting the folder on shortcuts.pictures has no effect at all.
    The first time i am opening the FileDialog it opens "Recently Used" and after that
    it always remembers the folder from which the data was picked the last time.

    Remembering the last folder would not be a problem for my usecase. But it is
    important that the pictures folder is picked when I am using the FileDialog the
    first time.

    And this does not happen.

    Any ideas how to fix this?



  • The default implementation for FileDialog is way too simple, and it doesn't count many of component's settings for some reason. Anyway, if you want to pick an image, you should use Intent.ACTION_GET_CONTENT Android API. This can be easily achieved from C++ using QtAndroid namespace and QAndroidJniObject (for 5.12 + versions).



  • @IntruderExcluder Thanks for your reply. Actually I am just using the pictures folder to open a Json file which I stored there before. I used the pictures folder because it's one of the standart paths which are writable. So my goal is selecting a specific folder. But I did not know that I can start Activities or Intents from c++. So if I manage to achieve it with native Android, can I just include the Activity in the code?

    Edit: Related to this stackoverflow answer there is no Intent which opens a particular folder in android.
    https://stackoverflow.com/questions/68224141/how-do-i-open-a-file-picker-at-the-applications-files-directory


Log in to reply