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. USB Storage detection and file read/write.
Forum Updated to NodeBB v4.3 + New Features

USB Storage detection and file read/write.

Scheduled Pinned Locked Moved Mobile and Embedded
8 Posts 6 Posters 4.4k Views 3 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.
  • Awadhesh MauryaA Offline
    Awadhesh MauryaA Offline
    Awadhesh Maurya
    wrote on last edited by
    #1

    Hi,
    I want to detect pen drive plugin in Qt application and file read/write to it.
    Please let suggest me about it. I am using Qt4.8.

    p3c0P 1 Reply Last reply
    0
    • Awadhesh MauryaA Awadhesh Maurya

      Hi,
      I want to detect pen drive plugin in Qt application and file read/write to it.
      Please let suggest me about it. I am using Qt4.8.

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @Awadhesh-Maurya Which OS are you targetting ? If Linux and if it has UDisks daemon running then use qdbus. Check this blog for more info.

      157

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

        Hi,

        To stay cross-platform your can consider the use of KDE's Solid library

        Hope it helps

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

        V 1 Reply Last reply
        1
        • K Offline
          K Offline
          kevfu
          wrote on last edited by
          #4

          @SGaist , do you know if the kde solid library is something I can use if I am planning to deploy to mac, windows and linux?

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

            Yes it is

            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
            • G Offline
              G Offline
              GeorgePTVS
              wrote on last edited by
              #6

              I was able to use a timer to keep looking at QDir::drives() to check for changes in the list. Works on Windows 7; I am making no claims for other platforms. Here's some code:

              I call initFileSystem() from elsewhere initially.

              void MyWidget::initFileSystem()
              {
                if (mFileSystemModel)
                  delete mFileSystemModel;
                mFileSystemModel = new QFileSystemModel(qApp);
                initListView(true);  // this just clears the view and sets its root to match the file model
                if ( !mDriveWatcherInitialized )
                  initDriveWatcher();
              }
              
              
              void MyWidget::initDriveWatcher()
              {
                bool connected = true;
                mDriveWatcherTimer = new QTimer(this);
                mDriveWatcherTimer->setInterval(DRIVE_WATCHER_TIMER_MILLISECONDS);  // e.g. 300 - 500 ms
                connected &= connect(mDriveWatcherTimer, SIGNAL(timeout()), this, SLOT(checkForDriveChanges())) != nullptr;
                mDriveWatcherTimer->start();
                mDriveWatcherInitialized = true;
              }
              
              void MyWidget::checkForDriveChanges()
              {
                // skip on/near startup
                static const int NUM_TIMES_TO_SKIP_DRIVE_CHANGE_CHECK = 5;
                static int timesThrough = 0;
                if (timesThrough++ < NUM_TIMES_TO_SKIP_DRIVE_CHANGE_CHECK)
                  return;
              
                static QFileInfoList originalFileInfoList = QDir::drives();
                QFileInfoList currentFileInfoList = QDir::drives();
                bool drivesChanged = false;
                // quick easy check
                if (currentFileInfoList.size() != originalFileInfoList.size())
                {
                  drivesChanged = true;
                }
                else
                {
                  // harder brute force check
                  int numMatches = 0;
                  foreach(QFileInfo currentFileInfo, currentFileInfoList)
                  {
                    foreach(QFileInfo originalFileInfo, originalFileInfoList)
                    {
                      if (currentFileInfo.absolutePath() == originalFileInfo.absolutePath())
                      {
                        numMatches++;
                        break;
                      }
                    }  // foreach(QFileInfo originalFileInfo, originalFileInfoList)
                  }  // foreach(QFileInfo currentFileInfo, currentFileInfoList)
              
                  if (numMatches != currentFileInfoList.size())
                    drivesChanged = true;
                }  // else
                if (drivesChanged)
                {
                  initFileSystem();  // this is what kicks the model
                  originalFileInfoList = QDir::drives();
                }
              }  // void MyWidget::checkForDriveChanges()
              
              1 Reply Last reply
              0
              • SGaistS SGaist

                Hi,

                To stay cross-platform your can consider the use of KDE's Solid library

                Hope it helps

                V Offline
                V Offline
                veer
                wrote on last edited by
                #7

                @SGaist said in USB Storage detection and file read/write.:

                KDE's Solid

                kindly help me to compile it please , I am facing problem to do it

                SGaistS 1 Reply Last reply
                0
                • V veer

                  @SGaist said in USB Storage detection and file read/write.:

                  KDE's Solid

                  kindly help me to compile it please , I am facing problem to do it

                  SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @veer hi, without any information, it's not possible to help you.

                  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

                  • Login

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