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. [Solved .. kind of] Getting event when USB is attached/detached
Forum Updated to NodeBB v4.3 + New Features

[Solved .. kind of] Getting event when USB is attached/detached

Scheduled Pinned Locked Moved Mobile and Embedded
17 Posts 4 Posters 8.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.
  • McLionM Offline
    McLionM Offline
    McLion
    wrote on last edited by
    #5

    Does somebody know this? http://sourceforge.net/projects/qdevicewatcher/

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #6

      If you have udisks running on the embedded system then you could use QDbus to get events.

      157

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

        No udisk and no Dbus ... unfortunately

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

          also looked at libusb ...
          which is listing in TODO:_ notifications of hotplugged/unplugged devices_
          So, this seems not to work either :(

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #9

            Do you have udev running ?

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

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

              Nope, running Busybox with mdev.
              Were you thinking about libudev ... me to ;)

              How about having QFileSystemWatcher monitoring /dev and getting an event when a sd?? is added .. could that work? ... I never used QFileWatcher before.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #11

                IIRC, not all filesystems on linux can be watched, thinking of /dev and /sys if my memory serves well. However, you could also simply poll dev for known device, not really efficient but might be simpler

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

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

                  Setting a watcher on /dev works as supposed.
                  Plugging a USB memory stick adds 5 entries in /dev which are removed again if the device is unplugged. The directoryChanged signal is emitted 17 times for plugging and 5 times for unplugging.
                  However, since the signal does not contain the information of what exactly the change in /dev was, I would need to maintain a list of the contents of /dev to be able to compare ... /dev has about 150 entries ... doing this for every emit ... I'm not sure if this is a good idea nor do I already have a solid idea on a efficient solution for doing this.

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #13

                    You could keep a list of /dev's content when starting to watch and then compare it to the current content when getting the directoryChanged signal. You can couple that with a QTimer to avoid a burst of your slot

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

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

                      Just did a test to debug output with this solution which could be a starting point to work something out:

                      @void QTGUI_MainWindow::showModifiedDirectory(QString directory)
                      {
                      qDebug() << "directory changed:" << directory;
                      QDir dir(directory);
                      if(dir.exists("sda1")) { qDebug() << "sda1 found!"; }
                      if(dir.exists("sdb1")) { qDebug() << "sdb1 found!"; }
                      }
                      @

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

                        Just like to add that this works as proposed using QFileSystemWatcher used to monitor the /dev. On the event I do some filtering using QDir … that’s it.

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          andreyc
                          wrote on last edited by
                          #16

                          There is a "a device watcher":http://qt-project.org/forums/viewthread/9605/ library.
                          I have not tried it.

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

                            Thanks for the hint. I have already checked this and looked at it. It's based on udev. Since my device uses busybox with mdev, I decided to not try to make this run and try my own solution instead.

                            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