Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-117460

Android FileDialog: 2nd and subsequent nameFilters are ignored

    XMLWordPrintable

Details

    • Android
    • 1989e419a (tqtc/lts-6.5)

    Description

      It looks like when multiple nameFilters are specified, only the first one is applied.

       

       Code

      import QtQuick 2.15
      import QtQuick.Window 2.15
      import QtQuick.Controls 2.15
      import QtQuick.Dialogs 1.3 // Remove version number to run on Qt 6
      
      Window {
          visible: true
      
          FileDialog {
              id: dialog
              onAccepted: console.log("Selected", dialog.fileUrl)
          }
      
          Column {
              Button {
                  id: b1
                  text: "*.txt only"
                  onClicked: {
                      dialog.nameFilters = ["(*.txt)"]
                      dialog.open()
                  }
              }
              Button {
                  id: b2
                  text: "*.csv only"
                  onClicked: {
                      dialog.nameFilters = ["(*.csv)"]
                      dialog.open()
                  }
              }
              Button {
                  id: b3
                  text: "*.txt and *.csv"
                  onClicked: {
                      dialog.nameFilters = ["(*.txt)", "(*.csv)"]
                      dialog.open()
                  }
              }
              Button {
                  id: b4
                  text: "*.csv and *.txt"
                  onClicked: {
                      dialog.nameFilters = ["(*.csv)", "(*.txt)"]
                      dialog.open()
                  }
              }
              Button {
                  id: b5
                  text: "*.txt and *.invalid"
                  onClicked: {
                      dialog.nameFilters = ["(*.txt)", "(*.invalid)"]
                      dialog.open()
                  }
              }
              Button {
                  id: b6
                  text: "*.invalid and *.txt"
                  onClicked: {
                      dialog.nameFilters = ["(*.invalid)", "(*.txt)"]
                      dialog.open()
                  }
              }
          }
      }
      

       

      Steps to reproduce

      1. On the Android device, use a web browser to download a *.txt and a *.csv file (samples attached)
      2. Build and run the code above
      3. Click each button and use the file picker to view/select the files you downloaded in Step #1

       

      Outcomes

      Button Expected selectable Actual selectable Result
      b1 *.txt *.txt Pass
      b2 *.csv *.csv Pass
      b3 *.txt and *.csv *.txt Fail
      b4 *.txt and *.csv *.csv Fail
      b5 *.txt *.txt Pass
      b5 *.txt (nothing) Fail

       

      Workaround

      Specify the file extensions as a single filter. Replace ["(*.txt)", "(*.csv)"] with ["(*.txt, *.csv)"]

      Attachments

        1. hello.csv
          0.0 kB
        2. hello.txt
          0.0 kB
        For Gerrit Dashboard: QTBUG-117460
        # Subject Branch Project Status CR V

        Activity

          People

            hurlevent Oliver Eftevaag
            skoh-qt Sze Howe Koh
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes