本文整理汇总了C++中QDir::drives方法的典型用法代码示例。如果您正苦于以下问题:C++ QDir::drives方法的具体用法?C++ QDir::drives怎么用?C++ QDir::drives使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDir
的用法示例。
在下文中一共展示了QDir::drives方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_ROdevicesInfo
QStringList Misc::get_ROdevicesInfo()
{
QStringList deviceInfo;
QDir dirs;
foreach (const QFileInfo drivesList, dirs.drives()){
qDebug() << drivesList.absolutePath();
}
foreach (const QStorageInfo &deviceList, QStorageInfo::mountedVolumes()){
if (deviceList.isValid() /*&& deviceList.isReady()*/) {
if (deviceList.isReadOnly()) {
QString item, itemDisplayNameFix;
item.append("Device: " + deviceList.device() + "\n");
deviceName << deviceList.device();
itemDisplayNameFix = deviceList.displayName();
itemDisplayNameFix.replace("\\x20", " ");
item.append("Label: " + itemDisplayNameFix + "\n");
item.append("Size: " + QString::number(deviceList.bytesTotal()/1024/1024) + " MB" + "\n"); // Convert to MB
item.append("State: Ready\n");
deviceInfo << item;
}
}
}
return deviceInfo;
}
示例2: foreach
hardDisk *Misc::get_HardDrivesInfo()
{
QStringList deviceInfo;
QDir dirs;
QString item;
foreach (const QFileInfo drivesList, dirs.drives()){
qDebug() << "Drive List: " << drivesList.absolutePath();
}
int i=0;
foreach (const QStorageInfo &deviceList, QStorageInfo::mountedVolumes()){
if (deviceList.isValid() && deviceList.isReady()) {
if (!deviceList.isReadOnly()) {
i++;
}
}
}
hddListCounter = i;
hardDisk* hardDiskStruc = new hardDisk[i];
i=0;
foreach (const QStorageInfo &deviceList, QStorageInfo::mountedVolumes()){
if (deviceList.isValid() && deviceList.isReady()) {
if (!deviceList.isReadOnly()) {
QString itemDisplayNameFix;
// deviceName << deviceList.device();
itemDisplayNameFix = deviceList.displayName();
itemDisplayNameFix.replace("\\x20", " ");
item.append("Label: " + itemDisplayNameFix + "\n");
item.append("Device: " + deviceList.device() + "\n");
qint64 total_diskSize = deviceList.bytesTotal();
qint64 total_diskSize_temp = 0;
while (total_diskSize >= 1024) {
total_diskSize_temp = total_diskSize/1024;
total_diskSize = total_diskSize_temp;
}
item.append("Total: " + QString::number(total_diskSize) + " Gb" + "\n"); // Convert to Gb
qint64 free_diskSize = deviceList.bytesFree();
qint64 free_diskSize_temp = 0;
while (free_diskSize >= 1024) {
free_diskSize_temp = free_diskSize/1024;
free_diskSize = free_diskSize_temp;
}
item.append("Free: " + QString::number(free_diskSize) + " Gb" + "\n"); // Convert to Gb
item.append("State: Ready\n\n");
deviceInfo << item;
hardDiskStruc[i].label = itemDisplayNameFix;
hardDiskStruc[i].device = deviceList.device();
hardDiskStruc[i].totalBytes = QString::number(total_diskSize);
hardDiskStruc[i].freeBytes = QString::number(free_diskSize);
hardDiskStruc[i].state = "Ready";
++i;
}
}
}
for (int var = 0; var < i; var++) {
qDebug() << "Label -" << hardDiskStruc[var].label;
qDebug() << "Device -" << hardDiskStruc[var].device;
qDebug() << "Total -" << hardDiskStruc[var].totalBytes << "Gb";
qDebug() << "Free -" << hardDiskStruc[var].freeBytes << "Gb";
qDebug() << "State -" << hardDiskStruc[var].state;
qDebug() << "------ empty line ------";
}
return hardDiskStruc;
}