How to get drive type in Qt
Hello everyone.
How can i get the list of all drives ( both removable and non-removable ) in my system and know which drive belongs to which drive type (as in removable or other drive types such as hdd, floppy disk etc ).
we have a simple class in C# called DriveInfo which gives a very detailed and easy to use methods for such tasks . I wonder if we have something like that in Qt.
Regards in advance
Re: How to get drive type in Qt
You have QDir::drives() and then winapi GetDriveType
Re: How to get drive type in Qt
Quote:
Originally Posted by
Zlatomir
Thank you but I am seeking a platform independent solution .
Re: How to get drive type in Qt
There's a class called QSystemStorageInfo in the Qt Mobility API.
You can use this as a base and extend it for other systems.
Qt doesn't have any other capability that does this, as far as I know.
There might be third party classes though.
Re: How to get drive type in Qt
found this thread and had the same problem (windows...)
Since Qt 5.4 you can use following:
http://doc.qt.io/qt-5/qstorageinfo.html#device
QByteArray QStorageInfo::device() const
Code:
Returns the device for this volume.
For example, on Unix filesystems (including OS X), this returns the devpath like [B]/dev/sda0[/B] for local storages.
On Windows, it returns the UNC path starting with [B]\\\\?\\ [/B]for local storages (in other words, the volume GUID).
For example:
Code:
bool bLocalDrive = false;
QStorageInfo storage(qApp->applicationDirPath());
/*
storage.device() returns the device for this volume.
For example, on Unix filesystems (including OS X), this returns the devpath like /dev/sda0 for local storages.
On Windows, it returns the UNC path starting with \\\\?\\ for local storages (in other words, the volume GUID).
*/
#ifdef Q_OS_WIN
if (qbaPath.startsWith("\\\\?\\"))
bLocalDrive = true;
#else
if (qbaPath.startsWith("/dev/sda0"))
bLocalDrive = true;
#endif
Re: How to get drive type in Qt
Well, on Unix local devices can have more names than just "sda0" :)
"sda0" is "scsi/sata disk a, parition 0"
You will probably want to check for "/dev/" or use Solid
Cheers,
_