How can I get read information from my harddisk in QT



  • I didn't find any api in QT to read information from my harddisk,so I use windows api GetVolumeInformation.but it return false.get the harddisk information failed.Following codes is how I use the api.
    @LPCTSTR lpRootPathName = L"c:\";
    LPWSTR volumeNameBuffer;
    DWORD nVolumeNameSize = 12;
    DWORD VolumeSerialNumber;
    DWORD MaximumComponentLength;
    LPWSTR fileSystemNameBuffer;
    DWORD nFileSystemNameSize = 10;
    DWORD FileSystemFlags;
    if(!GetVolumeInformation(lpRootPathName,
    volumeNameBuffer, nVolumeNameSize,
    &VolumeSerialNumber, &MaximumComponentLength,
    &FileSystemFlags,
    fileSystemNameBuffer, nFileSystemNameSize))
    return false;@


  • Lifetime Qt Champion

    Hi,

    depending on your version of Qt you could use QSystemStorage from QtMobility.

    Anyway nVolumeNameSize and nFileSystemNameSize are looking arbitrary short. A better place for Windows API question is the MSDN forum



  • I find the problem.I rewrite the code as:
    @
    LPCTSTR lpRootPathName = L"c:\"; // 取C盘
    LPTSTR volumeNameBuffer = new TCHAR[12]; // 磁盘卷标
    DWORD nVolumeNameSize = 12; // 卷标的字符串长度
    DWORD VolumeSerialNumber; // 硬盘序列号
    DWORD MaximumComponentLength; // 最大的文件长度
    LPTSTR fileSystemNameBuffer = new TCHAR[10]; // 存储所在盘符的分区类型的长指针变量
    DWORD nFileSystemNameSize = 10; // 分区类型的长指针变量所指向的字符串长度
    DWORD FileSystemFlags; // 文件系统的一此标志
    @
    I return what I want.But I don't know why.


  • Lifetime Qt Champion

    Then you should re-read the documentation of "GetVolumeInformation":http://msdn.microsoft.com/en-us/library/windows/desktop/aa364993(v=vs.85).aspx


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.