Results 1 to 6 of 6

Thread: How to get drive type in Qt

  1. #1
    Join Date
    Sep 2012
    Location
    Iran
    Posts
    34
    Thanks
    33
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default 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

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to get drive type in Qt

    You have QDir::drives() and then winapi GetDriveType

  3. The following user says thank you to Zlatomir for this useful post:

    Hossein (1st September 2012)

  4. #3
    Join Date
    Sep 2012
    Location
    Iran
    Posts
    34
    Thanks
    33
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to get drive type in Qt

    Quote Originally Posted by Zlatomir View Post
    You have QDir::drives() and then winapi GetDriveType
    Thank you but I am seeking a platform independent solution .

  5. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default 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.

  6. The following user says thank you to tbscope for this useful post:

    Hossein (1st September 2012)

  7. #5
    Join Date
    Aug 2016
    Posts
    1
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default 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

    Qt Code:
    1. Returns the device for this volume.
    2.  
    3. For example, on Unix filesystems (including OS X), this returns the devpath like [B]/dev/sda0[/B] for local storages.
    4. On Windows, it returns the UNC path starting with [B]\\\\?\\ [/B]for local storages (in other words, the volume GUID).
    To copy to clipboard, switch view to plain text mode 

    For example:

    Qt Code:
    1. bool bLocalDrive = false;
    2. QStorageInfo storage(qApp->applicationDirPath());
    3. /*
    4.   storage.device() returns the device for this volume.
    5.   For example, on Unix filesystems (including OS X), this returns the devpath like /dev/sda0 for local storages.
    6.   On Windows, it returns the UNC path starting with \\\\?\\ for local storages (in other words, the volume GUID).
    7.   */
    8. QByteArray qbaPath = storage.device();
    9. #ifdef Q_OS_WIN
    10. if (qbaPath.startsWith("\\\\?\\"))
    11. bLocalDrive = true;
    12. #else
    13. if (qbaPath.startsWith("/dev/sda0"))
    14. bLocalDrive = true;
    15. #endif
    To copy to clipboard, switch view to plain text mode 

  8. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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,
    _

Similar Threads

  1. How to Un- Initialize the drive in xp?
    By Gokulnathvc in forum Newbie
    Replies: 3
    Last Post: 12th May 2011, 23:45
  2. Drive sql
    By lucasbemo in forum Newbie
    Replies: 3
    Last Post: 4th November 2010, 18:33
  3. How to get the Drive letter
    By newb in forum Qt Programming
    Replies: 10
    Last Post: 10th June 2010, 13:59
  4. Need help on mount nfs drive in Qt
    By tho97 in forum Qt Programming
    Replies: 3
    Last Post: 28th November 2007, 19:26
  5. problem of how to get drive
    By jyoti in forum General Programming
    Replies: 6
    Last Post: 30th November 2006, 14:18

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.