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. QStorageInfo signal when # volumes changes?
Forum Updated to NodeBB v4.3 + New Features

QStorageInfo signal when # volumes changes?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 528 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.
  • D Offline
    D Offline
    davecotter
    wrote on last edited by
    #1

    I want a signal when a storage volume comes online or goes offline, so i can update my gui. This is NOT about USB, it's about file systems (which may connect via protocols other than USB).

    Basically i want to know when calling QStorageInfo::mountedVolumes() would give me a different number than before, and some ID of what volume it is (was).

    on mac this corresponds to listening for kEventVolumeMounted or kEventVolumeUnmounted
    on windows listen for WM_DEVICECHANGE: DBT_DEVICEARRIVAL, DBT_DEVICEREMOVECOMPLETE

    I'd be find just doing THAT if i knew how to add cocoa or win32 API specific code to my app, so if you know how to do THAT that would help.

    Whither this signal?

    1 Reply Last reply
    1
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #2

      You can use Solid.

      Solid::DeviceNotifier *notifier = Solid::DeviceNotifier::instance();
      const auto checkVolumeChange = [](const QString& uid, bool added){
          Solid::Device addedDevice(uid);
          if(!addedDevice.is<Solid::StorageVolume>())
              return;
          qDebug() << "Volume " << addedDevice.displayName() << added ? QStringLiteral("Added") : QStringLiteral("Removed");
      };
      QObject::connect(notifier,&Solid::DeviceNotifier::deviceAdded, std::bind(checkVolumeChange,std::placeholders::_1,true));
      QObject::connect(notifier,&Solid::DeviceNotifier::deviceRemoved, std::bind(checkVolumeChange,std::placeholders::_1,false));

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      2
      • D Offline
        D Offline
        davecotter
        wrote on last edited by
        #3

        does this "Solid" work on both mac and windows? Note i'm not developing for linux at all.

        KroMignonK 1 Reply Last reply
        0
        • D davecotter

          does this "Solid" work on both mac and windows? Note i'm not developing for linux at all.

          KroMignonK Offline
          KroMignonK Offline
          KroMignon
          wrote on last edited by
          #4

          @davecotter said in QStorageInfo signal when # volumes changes?:

          does this "Solid" work on both mac and windows?

          From https://api.kde.org/frameworks/solid/html/

          0cf58466-754d-4b04-be05-4443f37580c9-image.png

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          1 Reply Last reply
          1
          • D Offline
            D Offline
            davecotter
            wrote on last edited by
            #5

            so there's no way to do it within the existing Qt frameworks?

            VRoninV 1 Reply Last reply
            0
            • D davecotter

              so there's no way to do it within the existing Qt frameworks?

              VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by VRonin
              #6

              @davecotter said in QStorageInfo signal when # volumes changes?:

              the existing Qt frameworks?

              Not that I know of.

              Note that KDE and Qt have their destinies very tangled together, the KDE API maintainers are also maintainers within Qt, some classes made the jump from KDE API to Qt too (e.g. QConcatenateTablesProxyModel). KDE API is to Qt what Boost is to the C++ standard library

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              1 Reply Last reply
              1
              • D Offline
                D Offline
                davecotter
                wrote on last edited by
                #7

                thanks for the reassurance, i was hesitant when i saw it was a 3rd party package. I'll give it a try!

                1 Reply Last reply
                0
                • KH-219DesignK Offline
                  KH-219DesignK Offline
                  KH-219Design
                  wrote on last edited by
                  #8

                  I'm glad this question was posed (and answered)! I could have made use of this in the past, and hopefully will do so in the future.

                  Looks like the code is LGPL, too: https://invent.kde.org/frameworks/solid/-/blob/master/LICENSES/LicenseRef-KDE-Accepted-LGPL.txt

                  www.219design.com
                  Software | Electrical | Mechanical | Product Design

                  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