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.8k 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.
  • sierdzioS Offline
    sierdzioS Offline
    sierdzio
    Moderators
    wrote on 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
    3
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #3

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

      (Z(:^

      1 Reply Last reply
      1
      • sierdzioS sierdzio

        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 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
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on 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 last edited by
            #6

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

            1 Reply Last reply
            1
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on 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
              1
              • SGaistS SGaist

                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 last edited by
                #8

                @SGaist You mean the entire Qt project?

                K 1 Reply Last reply
                0
                • H hackkitten

                  @SGaist You mean the entire Qt project?

                  K Offline
                  K Offline
                  koahnig
                  wrote on 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
                  0
                  • K koahnig

                    @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 last edited by
                    #10

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

                    mrjjM 1 Reply Last reply
                    2
                    • H hackkitten

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

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 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
                      0
                      • mrjjM mrjj

                        @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 last edited by
                        #12

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

                        mrjjM 1 Reply Last reply
                        2
                        • H hackkitten

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

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #13

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

                          H 1 Reply Last reply
                          0
                          • mrjjM mrjj

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

                            H Offline
                            H Offline
                            hackkitten
                            wrote on 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
                            0
                            • H hackkitten

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

                              • Login

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