static void test_systemstorageinfo(void) { QSystemStorageInfo storageinfo; QStringList lst = storageinfo.logicalDrives(); qDebug() << "storageinfo.logicalDrives ->" << lst; for(int i = 0; i < lst.size(); ++i) { const QString &drv = lst.at(i); qDebug() << "Logical drive:" << drv; qlonglong avail = storageinfo.availableDiskSpace(drv); qDebug() << " storageinfo.availableDiskSpace() ->" << human_size(avail); qlonglong total = storageinfo.totalDiskSpace(drv); qDebug() << " storageinfo.totalDiskSpace() ->" << human_size(total); QSystemStorageInfo::DriveType dtype = storageinfo.typeForDrive(drv); qDebug() << " storageinfo.typeForDrive() ->" << dtype; QString duri = storageinfo.uriForDrive(drv); qDebug() << " storageinfo.uriForDrive() ->" << duri; QSystemStorageInfo::StorageState dstate = storageinfo.getStorageState(drv); qDebug() << " storageinfo.getStorageState() ->" << dstate; } }
void Dialog::setupStorage() { QSystemStorageInfo mi; storageTreeWidget->clear(); storageTreeWidget->header()->setResizeMode(QHeaderView::ResizeToContents); QStringList vols = mi.logicalDrives(); foreach(QString volName, vols) { QString type; QSystemStorageInfo::DriveType volType; volType = mi.typeForDrive(volName); if(volType == QSystemStorageInfo::InternalDrive) { type = "Internal"; } if(volType == QSystemStorageInfo::RemovableDrive) { type = "Removable"; } if(volType == QSystemStorageInfo::CdromDrive) { type = "Cdrom"; } if(volType == QSystemStorageInfo::RemoteDrive) { type = "Network"; } QStringList items; items << volName; items << type; items << QString::number(mi.totalDiskSpace(volName)); items << QString::number(mi.availableDiskSpace(volName)); QTreeWidgetItem *item = new QTreeWidgetItem(items); storageTreeWidget->addTopLevelItem(item); }