Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] How to detect USB devices
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] How to detect USB devices

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 5 Posters 17.2k Views 2 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.
  • alsaA Offline
    alsaA Offline
    alsa
    wrote on last edited by alsa
    #1

    My aim is to save a txt file from my Qt app to an external device (SD card, USB pendrive...). The app is created for an embedded system.
    My problem is: how detect which USB device is connected when I inserted a USB pen, in such a way that I can save my file in it?
    Which is the best method using Qt?

    1 Reply Last reply
    0
    • McLionM Offline
      McLionM Offline
      McLion
      wrote on last edited by
      #2

      Usually, mounting storage devices is handled by the OS.
      What is the target OS for which you are developing?

      1 Reply Last reply
      0
      • alsaA Offline
        alsaA Offline
        alsa
        wrote on last edited by alsa
        #3

        I'm developing on Ubuntu 14.04 for a Single Board Computer Variscite (its OS is Linux-embedded)

        McLionM 1 Reply Last reply
        0
        • R Offline
          R Offline
          Renn
          wrote on last edited by
          #4

          If your goal is only to store data, use this command QFileDialog::getSaveFileName(); If your goal is only to store data, use this command. Do not forget the file header #include <QFileDialog>

          1 Reply Last reply
          0
          • alsaA alsa

            I'm developing on Ubuntu 14.04 for a Single Board Computer Variscite (its OS is Linux-embedded)

            McLionM Offline
            McLionM Offline
            McLion
            wrote on last edited by McLion
            #5

            @alsa
            Does your eLinux mount newly attached storage devices automatically to a mount point or does it only create a device file?

            I had the same task on eLinux as well. My system did create the device file only (busybox with mdev). I used a QFileSystemWatcher to detect changes in /dev, ie. attached sdan and acted on that with mounting/unmounting the device.

            1 Reply Last reply
            0
            • alsaA Offline
              alsaA Offline
              alsa
              wrote on last edited by
              #6

              It only creates a device file

              McLionM 1 Reply Last reply
              0
              • alsaA alsa

                It only creates a device file

                McLionM Offline
                McLionM Offline
                McLion
                wrote on last edited by
                #7

                @alsa
                Then look into QFileSystemWatcher.

                1 Reply Last reply
                1
                • McLionM Offline
                  McLionM Offline
                  McLion
                  wrote on last edited by
                  #8

                  To start:

                  // prepare FS watcher to detect added USB memory
                  FSwatcher = new QFileSystemWatcher(this);
                  FSwatcher->addPath("/dev");
                  connect(FSwatcher, SIGNAL(directoryChanged(QString)), this, SLOT(showModifiedDirectory(QString)));
                  

                  HTH
                  McL

                  J 1 Reply Last reply
                  2
                  • E Offline
                    E Offline
                    ealltech
                    wrote on last edited by
                    #9
                    This post is deleted!
                    1 Reply Last reply
                    0
                    • McLionM McLion

                      To start:

                      // prepare FS watcher to detect added USB memory
                      FSwatcher = new QFileSystemWatcher(this);
                      FSwatcher->addPath("/dev");
                      connect(FSwatcher, SIGNAL(directoryChanged(QString)), this, SLOT(showModifiedDirectory(QString)));
                      

                      HTH
                      McL

                      J Offline
                      J Offline
                      Jim S
                      wrote on last edited by
                      #10

                      @McLion Would you currently prefer this approach over Qt D-Bus for it's simplicity?

                      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