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. How to read files from usb flash drive using libusb libarary api's?
Forum Updated to NodeBB v4.3 + New Features

How to read files from usb flash drive using libusb libarary api's?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
11 Posts 3 Posters 3.0k Views 1 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.
  • R Offline
    R Offline
    Ronak5
    wrote on last edited by Ronak5
    #1

    Hi,

    I want to read files from usb device and I read somewhere that I've to use libusb library for it.
    Now using libusb api's I'm able to obtain the device handle and open it, But how do I read certain files from it and provide those files info to my Qt application?
    Thanks.

    jsulmJ J.HilkJ 2 Replies Last reply
    0
    • R Ronak5

      Hi,

      I want to read files from usb device and I read somewhere that I've to use libusb library for it.
      Now using libusb api's I'm able to obtain the device handle and open it, But how do I read certain files from it and provide those files info to my Qt application?
      Thanks.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by jsulm
      #2

      @Ronak5 There is absolutely no need for libusb to read/write files from/to USB flash drive.
      On Windows such a drive is mounted as a drive with its own drive letter. On Linux MacOS it is mounted somewhere in the file system (like /media/SUB_DRIVE). Just access it in the same way you do with an internal drive.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      R 1 Reply Last reply
      3
      • R Ronak5

        Hi,

        I want to read files from usb device and I read somewhere that I've to use libusb library for it.
        Now using libusb api's I'm able to obtain the device handle and open it, But how do I read certain files from it and provide those files info to my Qt application?
        Thanks.

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by J.Hilk
        #3

        @Ronak5 is this on android ?
        Because if it is, than neither Qt nor libusb will help you here. Android strictly prohibits access to external sdcard and/or usb devices.

        You'll have to use native java-api for this.


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        R 1 Reply Last reply
        3
        • jsulmJ jsulm

          @Ronak5 There is absolutely no need for libusb to read/write files from/to USB flash drive.
          On Windows such a drive is mounted as a drive with its own drive letter. On Linux MacOS it is mounted somewhere in the file system (like /media/SUB_DRIVE). Just access it in the same way you do with an internal drive.

          R Offline
          R Offline
          Ronak5
          wrote on last edited by
          #4

          @jsulm okay. But everytime the drive name while reading from /media/drive
          will be different. How do I obtain the inserted usb name? Also do I have to take care of permission also?

          jsulmJ 1 Reply Last reply
          1
          • J.HilkJ J.Hilk

            @Ronak5 is this on android ?
            Because if it is, than neither Qt nor libusb will help you here. Android strictly prohibits access to external sdcard and/or usb devices.

            You'll have to use native java-api for this.

            R Offline
            R Offline
            Ronak5
            wrote on last edited by
            #5

            @J.Hilk Hi, yes I also need to do this on android. So I've to use java-api to read those and extract the info in Qt app?
            Do you have any reference/ example to read about it? Thanks.

            J.HilkJ 1 Reply Last reply
            0
            • R Ronak5

              @jsulm okay. But everytime the drive name while reading from /media/drive
              will be different. How do I obtain the inserted usb name? Also do I have to take care of permission also?

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by jsulm
              #6

              @Ronak5 Permissions is something handled by the OS/filesystem, not USB.
              Regarding drive letter: I'm not sure what your use case is and what exactly you're doing. You can enumerate the drive letter using Qt, see https://doc.qt.io/qt-5/qstorageinfo.html

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              R 1 Reply Last reply
              2
              • R Ronak5

                @J.Hilk Hi, yes I also need to do this on android. So I've to use java-api to read those and extract the info in Qt app?
                Do you have any reference/ example to read about it? Thanks.

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #7

                @Ronak5
                this should help further:

                https://developer.android.com/training/data-storage/files.html#WriteExternalStorage


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                R 2 Replies Last reply
                4
                • jsulmJ jsulm

                  @Ronak5 Permissions is something handled by the OS/filesystem, not USB.
                  Regarding drive letter: I'm not sure what your use case is and what exactly you're doing. You can enumerate the drive letter using Qt, see https://doc.qt.io/qt-5/qstorageinfo.html

                  R Offline
                  R Offline
                  Ronak5
                  wrote on last edited by Ronak5
                  #8

                  @jsulm I intend to read the music and video format files from an usb device inserted and play those files. I'm able to play it on hard coding with the usb mounted name in /media. But I intend to make it generic without hard coding the mount name available in /media drive.

                  1 Reply Last reply
                  1
                  • J.HilkJ J.Hilk

                    @Ronak5
                    this should help further:

                    https://developer.android.com/training/data-storage/files.html#WriteExternalStorage

                    R Offline
                    R Offline
                    Ronak5
                    wrote on last edited by
                    #9

                    @J.Hilk thanks for help.

                    1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      Ronak5
                      wrote on last edited by Ronak5
                      #10

                      @jsulm hey, QStorageInfo is what helped me to get the mounted storage devices name. Thanks a lot for hints.

                      https://doc.qt.io/qt-5/qstorageinfo.html#details

                      1 Reply Last reply
                      1
                      • J.HilkJ J.Hilk

                        @Ronak5
                        this should help further:

                        https://developer.android.com/training/data-storage/files.html#WriteExternalStorage

                        R Offline
                        R Offline
                        Ronak5
                        wrote on last edited by
                        #11

                        @J.Hilk Hi, I was going through lib usb for android here https://libusb.info/
                        It says that "It is portable: Using a single cross-platform API, it provides access to USB devices on Linux, OS X, Windows, Android, OpenBSD, etc."

                        So , does it mean the linux implementation would work for android platform also?
                        I don't know how to include libusb libraries for android platform.
                        It

                        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