void fm_Import::ScanHD()
{
QFileInfoList list = QDir::drives(); //获取当前系统的盘符
QString path;
bool bUsb = false;
for(int i=0;i<list.count();i++){
path = list[i].filePath();
qDebug()<<path;
//windows API的头文件中,GetDriveType的参数是PCWCH或者LPCWCH类型,需要进行转换,
//查看typedef CONST WCHAR *LPCWCH, *PCWCH;
//typedef wchar_t WCHAR; // wc, 16-bit UNICODE character
UINT ret = GetDriveType((WCHAR *) path.utf16());
qDebug()<<ret;
if(ret == DRIVE_REMOVABLE){
qDebug()<<"存在可移动盘:"<<path;
bUsb = true;
this->AddDisk(path);
}
}
}
本文介绍了一个C++函数voidfm_Import::ScanHD(),该函数使用Qt和Windows API来扫描当前系统的所有盘符,查找并识别可移动磁盘。通过遍历QDir::drives()获取的盘符列表,利用GetDriveType函数判断盘符类型,当发现可移动磁盘时,将其路径添加到磁盘列表。
1614

被折叠的 条评论
为什么被折叠?



