[Kde-hardware-devel] Solid - how to get path of storage device

Christopher Blauvelt cblauvelt at gmail.com
Wed Jun 11 04:10:43 CEST 2008


On Tue, Jun 10, 2008 at 7:31 PM, David Boosalis <david.boosalis at gmail.com>
wrote:

> Hi Chris.
>
> The signal gets generated from a USB being plugged in.  I use the following
> to connect the signal to the slog given:
>
>   connect(DeviceNotifier::instance(),
>       SIGNAL(deviceAdded(const QString &)),
>       this,
>       SLOT(slotSolidDeviceChanged(const QString &)));
>
>   connect(Solid::DeviceNotifier::instance(),
>       SIGNAL(deviceRemoved(const QString &)),
>       this,
>       SLOT(slotSolidDeviceChanged(const QString &)));
>
> This was taken from the solid tutorial. Maybe I am getting an extraneous
> signal when I plug in the usb stick because the qDebug statement for
> filePath below prints nothing for hte filePath argument. I am using hte
> latest build of the depot for all my coding work.  You mentioned something
> about StorgeAccess::setup(), I'll research this call, as I am not sure where
> to put it.
>
> filePath() gives you the path to where the device is *mounted*.  The signal
you're receiving is sent when the device is plugged in, regardless of
whether it's mounted or not.  If you plug in your USB device, and it's not
mounted you catch the signal that a device was added but since it's not
mounted filePath() will return QString().

Try this in your slot:
qDebug() << "Device changed " << str;
  QString filePath;
  Solid::Device device(str);
  Solid::StorageAccess *accessStorage = device.as<Solid::StorageAccess>();
  if(storageAccess) {
     if(!storageAccess->isAccessible()) { //device is plugged in but not
mounted
         storageAccess->setup();
     }
     qDebug() << "File path is: " << storageAccess->filePath();
  }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.kde.org/pipermail/kde-hardware-devel/attachments/20080610/0070c8b2/attachment.html 


More information about the Kde-hardware-devel mailing list