PDA

View Full Version : Retrieving windows Drive labels



Baasie
12th August 2009, 00:04
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

LaOnze2000
18th August 2009, 20:26
Here is what I am using :




#include <qt_windows.h>

// Function to retrieve volume names

QString TvInfo(QString & tdrive)
{
WCHAR szVolumeName[256] ;
WCHAR szFileSystemName[256];
DWORD dwSerialNumber = 0;
DWORD dwMaxFileNameLength=256;
DWORD dwFileSystemFlags=0;
bool ret = GetVolumeInformation( (WCHAR *) tdrive.utf16(),szVolumeName,256,&dwSerialNumber,&dwMaxFileNameLength,&dwFileSystemFlags,szFileSystemName,256);
if(!ret)return QString("");
QString vName=QString::fromUtf16 ( (const ushort *) szVolumeName) ;
vName.trimmed();
return vName;
}


// Get volume name of c drive
QString tdrv="C:\\";
QString volume_name = TvInfo(tdrv);




Hope this helps
Murielle

Baasie
24th August 2009, 09:05
Thanx a lot, i am gonna try this today.