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. Reading content url on android QtQuick 5.15
Forum Update on Monday, May 27th 2025

Reading content url on android QtQuick 5.15

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
9 Posts 4 Posters 1.4k Views
  • 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.
  • C Offline
    C Offline
    cmorgan
    wrote on last edited by
    #1

    I am trying to read a file given to me by QFileDialog. This is the file returned
    0a9b092a-dd51-4468-8f61-135f8fe332ff-image.png

    I pass it to the c++ side but "filename" never returns anything

    55e77282-34d5-440c-8d19-48ccb6cecb7f-image.png

    Thanks in advance

    1 Reply Last reply
    0
    • ekkescornerE Offline
      ekkescornerE Offline
      ekkescorner
      Qt Champions 2016
      wrote on last edited by
      #2

      please take a look at these discussions:
      https://forum.qt.io/topic/113328/how-to-convert-android-content-url-and-use-it-to-open-file
      https://forum.qt.io/topic/113335/qfiledialog-getopenfilename-always-returns-empty-string-on-android

      ekke ... Qt Champion 2016 | 2024 ... mobile business apps
      5.15 --> 6.8 https://t1p.de/ekkeChecklist
      QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

      C 2 Replies Last reply
      1
      • ekkescornerE ekkescorner

        please take a look at these discussions:
        https://forum.qt.io/topic/113328/how-to-convert-android-content-url-and-use-it-to-open-file
        https://forum.qt.io/topic/113335/qfiledialog-getopenfilename-always-returns-empty-string-on-android

        C Offline
        C Offline
        cmorgan
        wrote on last edited by
        #3

        @ekkescorner I've read them both, the first one doesn't mention anything about content url's (thatI see anyway) and the latter has the same suggestion from the moderator

        1 Reply Last reply
        0
        • ekkescornerE ekkescorner

          please take a look at these discussions:
          https://forum.qt.io/topic/113328/how-to-convert-android-content-url-and-use-it-to-open-file
          https://forum.qt.io/topic/113335/qfiledialog-getopenfilename-always-returns-empty-string-on-android

          C Offline
          C Offline
          cmorgan
          wrote on last edited by
          #4

          @ekkescorner It seems to me the answer is "you don't"

          ekkescornerE 1 Reply Last reply
          0
          • C cmorgan

            @ekkescorner It seems to me the answer is "you don't"

            ekkescornerE Offline
            ekkescornerE Offline
            ekkescorner
            Qt Champions 2016
            wrote on last edited by
            #5

            @cmorgan I haven't tried native Android QFileDialog and Qt 5.15 yet - have to finish customer projects on 5.13.2 before
            But I have used a content url in my share example https://github.com/ekke/ekkesSHAREexample/blob/master/android/src/org/ekkescorner/utils/QSharePathResolver.java

            ekke ... Qt Champion 2016 | 2024 ... mobile business apps
            5.15 --> 6.8 https://t1p.de/ekkeChecklist
            QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

            1 Reply Last reply
            2
            • M Offline
              M Offline
              maitai_vw
              wrote on last edited by
              #6

              Hi,

              I am trying to use your nice QSharePathResolver class, but this time to resolve a directory name sent by QFileDialog::openExistingDirectory (native mode).

              This returns something in the form "content://com.android.externalstorage.documents/tree/home%3A" (just selected Documents directory on the phone).

              QSharePathResolver just throw an exception (catched) on that. How can I convert this to just a QDirectory?

              Running on qt 5.15.2, tested on Android 10 and 11

              Thanks for any clue,
              Philippe

              ekkescornerE 1 Reply Last reply
              0
              • M maitai_vw

                Hi,

                I am trying to use your nice QSharePathResolver class, but this time to resolve a directory name sent by QFileDialog::openExistingDirectory (native mode).

                This returns something in the form "content://com.android.externalstorage.documents/tree/home%3A" (just selected Documents directory on the phone).

                QSharePathResolver just throw an exception (catched) on that. How can I convert this to just a QDirectory?

                Running on qt 5.15.2, tested on Android 10 and 11

                Thanks for any clue,
                Philippe

                ekkescornerE Offline
                ekkescornerE Offline
                ekkescorner
                Qt Champions 2016
                wrote on last edited by
                #7

                @maitai_vw is on my todo list ;-)
                just too much work on customer projects (mobile apps Android, iOS)

                ekke ... Qt Champion 2016 | 2024 ... mobile business apps
                5.15 --> 6.8 https://t1p.de/ekkeChecklist
                QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

                M 1 Reply Last reply
                0
                • ekkescornerE ekkescorner

                  @maitai_vw is on my todo list ;-)
                  just too much work on customer projects (mobile apps Android, iOS)

                  M Offline
                  M Offline
                  Marek
                  wrote on last edited by
                  #8

                  @ekkescorner HI
                  I'm trying to use your example to get filePath from android content:/..
                  I'm using QSharePathResolver but since I don't know Java at all ;) I have trouble calling this method, can you give me some hint ?
                  Here is Qt code:

                  QString PostManager::getFilePath(QUrl url) {
                  #ifdef Q_OS_ANDROID
                      QAndroidJniObject jsPath = QAndroidJniObject::fromString(url.toLocalFile());
                      QAndroidJniObject uri = QAndroidJniObject::callStaticObjectMethod("android/net/Uri","parse","(Ljava/lang/String;)Landroid/net/Uri;", jsPath.object());
                      QString filename =
                            QAndroidJniObject::callStaticObjectMethod(
                                "org/ekkescorner/utils/QSharePathResolver", "getRealPathFromURI",
                                "(Landroid/content/Context;Landroid/net/Uri)Ljava/lang/String;",
                                QtAndroid::androidContext().object(),uri.object<jobject>()).toString();
                  

                  And here is debug from phone with the error:

                  W System.err: java.lang.NoSuchMethodError: no static method "Lorg/ekkescorner/utils/QSharePathResolver;.getRealPathFromURI(Landroid/content/Context;Landroid/net/Uri)Ljava/lang/String;"
                  W System.err: 	at org.qtproject.qt5.android.QtNative.startQtApplication(Native Method)
                  W System.err: 	at org.qtproject.qt5.android.QtNative$7.run(QtNative.java:620)
                  W System.err: 	at org.qtproject.qt5.android.QtThread$1.run(QtThread.java:61)
                  W System.err: 	at java.lang.Thread.run(Thread.java:923)
                  

                  Basically I need "file://..." to pass as videoSource for MediaPlayer, it can't read "content:/..."
                  Best Regards
                  Marek

                  1 Reply Last reply
                  0
                  • ekkescornerE Offline
                    ekkescornerE Offline
                    ekkescorner
                    Qt Champions 2016
                    wrote on last edited by
                    #9

                    @Marek sorry - cannot help immediately. ... working on 5 new highly complex mobile business apps (some with Bluetooth SPP Printer, some with BLE Scanner, one with Beacons) last months
                    hopefully soon more time for community
                    now because of Apple requiring XCode 12 I finally have to update my tooling...
                    next week I'll move from Qt 5.13.2 to 5.15 and from macOS Mojave to Catalina, XCode from 11 to 12, Android NDK, SDK, ...
                    will take some days until all projects running again ;-)
                    Then I'll have to take a look at using native Android QFileDialog and probably rewrite my Pathresolver
                    will let you know ...

                    ekke ... Qt Champion 2016 | 2024 ... mobile business apps
                    5.15 --> 6.8 https://t1p.de/ekkeChecklist
                    QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

                    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