Results 1 to 3 of 3

Thread: Retrieving windows Drive labels

  1. #1
    Join Date
    Aug 2009
    Posts
    29
    Thanked 1 Time in 1 Post

    Default Retrieving windows Drive labels

    Hello fellow programmers,

    i have been introducted to QT some while ago while i already had java and c++ experience. So programming in QT was easy to learn, and usually i find my way around problems or things i want. But here is the deal.

    To make a program that can read external devices such as SD cards or usb sticks is easy using the QDir, but i am making a program for a user who needs to load data from his device to the pc. Now for this i want to read out the drives on a windows system, also not hard to aquire using the next lines:

    foreach( QFileInfo drive, QDir::drives() )
    {
    qDebug() << "Drive: " << drive.absolutePath();
    }

    now this in return gives the Letters form the drives but not the name, wich i mean the label you can give in windows. This is nice to because user usually label there devies.

    So is there anyone here able to help me out. I tried sorts of things myself but i am not a professionol yet, just a normal programmer.

    thanx in advance

    Kenny Baas

  2. #2
    Join Date
    Mar 2007
    Posts
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt/Embedded
    Platforms
    MacOS X Windows

    Default Re: Retrieving windows Drive labels

    Here is what I am using :

    Qt Code:
    1. #include <qt_windows.h>
    2.  
    3. // Function to retrieve volume names
    4.  
    5. QString TvInfo(QString & tdrive)
    6. {
    7. WCHAR szVolumeName[256] ;
    8. WCHAR szFileSystemName[256];
    9. DWORD dwSerialNumber = 0;
    10. DWORD dwMaxFileNameLength=256;
    11. DWORD dwFileSystemFlags=0;
    12. bool ret = GetVolumeInformation( (WCHAR *) tdrive.utf16(),szVolumeName,256,&dwSerialNumber,&dwMaxFileNameLength,&dwFileSystemFlags,szFileSystemName,256);
    13. if(!ret)return QString("");
    14. QString vName=QString::fromUtf16 ( (const ushort *) szVolumeName) ;
    15. vName.trimmed();
    16. return vName;
    17. }
    18.  
    19.  
    20. // Get volume name of c drive
    21. QString tdrv="C:\\";
    22. QString volume_name = TvInfo(tdrv);
    To copy to clipboard, switch view to plain text mode 

    Hope this helps
    Murielle

  3. #3
    Join Date
    Aug 2009
    Posts
    29
    Thanked 1 Time in 1 Post

    Default Re: Retrieving windows Drive labels

    Thanx a lot, i am gonna try this today.

Similar Threads

  1. Replies: 5
    Last Post: 15th January 2009, 10:03

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.