Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QFileDialog::getOpenFileName always returns empty string on Android
Forum Updated to NodeBB v4.3 + New Features

QFileDialog::getOpenFileName always returns empty string on Android

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
15 Posts 5 Posters 3.5k Views 4 Watching
  • 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.
  • H Offline
    H Offline
    hackkitten
    wrote on 5 Apr 2020, 20:52 last edited by
    #1

    As the title says, I have working code (on Windows & Linux) that I compiled for Android. Everything works, except that when I try to open a local file, I cannot get file path back from getOpenFileName(). I do get the native Android (Android 8) file picker dialogue for local files, and I can select anything.

    Yet the return value is always an empty string. This happens with Qt 5.13.2 and 5.14.2, and with a somewhat older SDK & NDK, as well as the (as of writing) latest SDK & NDK.

    It's essentially the same issue as in this thread: https://forum.qt.io/topic/109548/android-qfiledialog-returns-nothing-and-code-in-background-keeps-running

    That thread never got a useful response or resolution, however. Am I to conclude that opening local files on Android using any of the QFileDialog methods is not functional on Android? The documentation sadly doesn't even list Android (or iOS).

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 7 Apr 2020, 04:51 last edited by
      #2

      It's been a while since I implemented file dialog in an Android app, so Unfortunately I don't have exact reply here. But maybe it will at least help you a bit.

      Here's what you (may) need:

      • make sure you request appropriate file access permissions in your Android manifest (WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE
      • use a file provider (android/res/xml/fileprovider.xml) with appropriate adnotations in AndroidManifest for it
      • use native code (Java) to "extract" file data from file provider using custom Intent
      • make sure to do a runtime check if user has granted the permission (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)))

      Sorry for being so vague, unfortunately I'm not allowed to share the code I've written (and it was written for different purpose - I'm not exactly certain it would work). Unfortunately, Android keeps making it harder and harder to access files :-(

      (Z(:^

      H 1 Reply Last reply 7 Apr 2020, 09:59
      3
      • S Offline
        S Offline
        sierdzio
        Moderators
        wrote on 7 Apr 2020, 05:43 last edited by
        #3

        Oh, a much better answer came up in this thread.

        (Z(:^

        1 Reply Last reply
        1
        • S sierdzio
          7 Apr 2020, 04:51

          It's been a while since I implemented file dialog in an Android app, so Unfortunately I don't have exact reply here. But maybe it will at least help you a bit.

          Here's what you (may) need:

          • make sure you request appropriate file access permissions in your Android manifest (WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE
          • use a file provider (android/res/xml/fileprovider.xml) with appropriate adnotations in AndroidManifest for it
          • use native code (Java) to "extract" file data from file provider using custom Intent
          • make sure to do a runtime check if user has granted the permission (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)))

          Sorry for being so vague, unfortunately I'm not allowed to share the code I've written (and it was written for different purpose - I'm not exactly certain it would work). Unfortunately, Android keeps making it harder and harder to access files :-(

          H Offline
          H Offline
          hackkitten
          wrote on 7 Apr 2020, 09:59 last edited by
          #4

          @sierdzio So essentially the issue is that Qt still uses Intents on Android for things like the filepicking dialogue, but doesn't implement the result handling?

          This seems like something that should be documented in the QFileDialog documentation and such places.

          I'm confused about in how far the "Sharing Files on Android or iOS from your Qt App" article applies as well here. Since calling those static functions in QFileDialog already seem to do the calling of an Intent, that would mean that one 'just' needs to add the part where one handles the result, no?

          My feeling here is still that this qualifies as a bug in Qt, if not of QFileDialog, then of the documentation.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sierdzio
            Moderators
            wrote on 7 Apr 2020, 10:31 last edited by
            #5

            You're very likely correct that it is a bug :-)

            (Z(:^

            1 Reply Last reply
            0
            • H Offline
              H Offline
              hackkitten
              wrote on 7 Apr 2020, 13:36 last edited by
              #6

              I have filed a bug report over at: https://bugreports.qt.io/browse/QTBUG-83372

              1 Reply Last reply
              1
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 7 Apr 2020, 18:29 last edited by
                #7

                Hi,

                Thanks for the report !

                Would you mind uploading your example directly on the report ? That allows to have everything in a single place.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                H 1 Reply Last reply 8 Apr 2020, 12:49
                1
                • S SGaist
                  7 Apr 2020, 18:29

                  Hi,

                  Thanks for the report !

                  Would you mind uploading your example directly on the report ? That allows to have everything in a single place.

                  H Offline
                  H Offline
                  hackkitten
                  wrote on 8 Apr 2020, 12:49 last edited by
                  #8

                  @SGaist You mean the entire Qt project?

                  K 1 Reply Last reply 8 Apr 2020, 12:54
                  0
                  • H hackkitten
                    8 Apr 2020, 12:49

                    @SGaist You mean the entire Qt project?

                    K Offline
                    K Offline
                    koahnig
                    wrote on 8 Apr 2020, 12:54 last edited by
                    #9

                    @hackkitten

                    Typically a small project showing the issue is enough.
                    If the developers have already such a small project it give them lead where to look at.

                    Vote the answer(s) that helped you to solve your issue(s)

                    H 1 Reply Last reply 11 Apr 2020, 12:58
                    0
                    • K koahnig
                      8 Apr 2020, 12:54

                      @hackkitten

                      Typically a small project showing the issue is enough.
                      If the developers have already such a small project it give them lead where to look at.

                      H Offline
                      H Offline
                      hackkitten
                      wrote on 11 Apr 2020, 12:58 last edited by
                      #10

                      @koahnig I have attached a simple demonstration project to the bug report.

                      mrjjM 1 Reply Last reply 11 Apr 2020, 14:04
                      2
                      • H hackkitten
                        11 Apr 2020, 12:58

                        @koahnig I have attached a simple demonstration project to the bug report.

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 11 Apr 2020, 14:04 last edited by
                        #11

                        @hackkitten
                        Omg, Miss Maya Posch
                        believe or not, your post been mention a million times :)
                        https://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/

                        H 1 Reply Last reply 13 Apr 2020, 08:44
                        0
                        • mrjjM mrjj
                          11 Apr 2020, 14:04

                          @hackkitten
                          Omg, Miss Maya Posch
                          believe or not, your post been mention a million times :)
                          https://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/

                          H Offline
                          H Offline
                          hackkitten
                          wrote on 13 Apr 2020, 08:44 last edited by
                          #12

                          @mrjj I'll believe it, based on the traffic stats to my programming blog :)

                          mrjjM 1 Reply Last reply 13 Apr 2020, 08:57
                          2
                          • H hackkitten
                            13 Apr 2020, 08:44

                            @mrjj I'll believe it, based on the traffic stats to my programming blog :)

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on 13 Apr 2020, 08:57 last edited by
                            #13

                            @hackkitten
                            Hehe yeah and comments all the way from 2011 to 2019 :)

                            H 1 Reply Last reply 19 Apr 2020, 15:44
                            0
                            • mrjjM mrjj
                              13 Apr 2020, 08:57

                              @hackkitten
                              Hehe yeah and comments all the way from 2011 to 2019 :)

                              H Offline
                              H Offline
                              hackkitten
                              wrote on 19 Apr 2020, 15:44 last edited by
                              #14

                              @mrjj Quite a few comments that I should be looking into to update the blog post, too, perhaps :)

                              Sadly it seems that Qt even after 9 years hasn't seen the need to meaningfully update their documentation for things like QThread. Now with Android the situation is even worse, with very little documentation to be found.

                              At any rate I hope that this bug in QFileDialog can be resolved soon, because right now it's a blocker for Qt on Android in my project. I may have to go back to just using Java there again, which would be somewhat sad.

                              mrjjM 1 Reply Last reply 19 Apr 2020, 15:58
                              0
                              • H hackkitten
                                19 Apr 2020, 15:44

                                @mrjj Quite a few comments that I should be looking into to update the blog post, too, perhaps :)

                                Sadly it seems that Qt even after 9 years hasn't seen the need to meaningfully update their documentation for things like QThread. Now with Android the situation is even worse, with very little documentation to be found.

                                At any rate I hope that this bug in QFileDialog can be resolved soon, because right now it's a blocker for Qt on Android in my project. I may have to go back to just using Java there again, which would be somewhat sad.

                                mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on 19 Apr 2020, 15:58 last edited by
                                #15

                                Hi
                                Well yes, perhaps :)
                                well they did add a worker example to the docs
                                https://doc.qt.io/qt-5/qthread.html
                                Also after years of shouting at people that would subclass QThread, then the fight died out with
                                https://woboq.com/blog/qthread-you-were-not-doing-so-wrong.html
                                So the docs show both ways.

                                Well bug fixing is a bit slow so might take some time to get a fix for the android
                                QFileDialog thing but it should come at some point.

                                I have not done much with java, but recently fooled around with Flutter and
                                found it very nice to work with. If only it had a WYSIWYG editor i would be sold. :)

                                But yeah, it would be sad your Qt project would be blocked and abandoned just due to a silly bug.

                                1 Reply Last reply
                                0

                                1/15

                                5 Apr 2020, 20:52

                                • Login

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