C++ Class

하드디스크 드라이브 여유 공간 계산

by makersweb posted Jan 15, 2023
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄

QStorageInfo 클래스를 사용하면 하드디스크 정보를 가져와서 여유공간 등의 정보를 알 수 있다. 아래 예제에서는 애플리케이션이 Windows 볼륨(C:드라이브) 정보를 가져오는 방법을 보여준다.

#include <QDebug>

#include <QStorageInfo>

#define GB (1024 * 1024 * 1024)

void PrintVolumeInfo(const QString &drive)
{
    QStorageInfo storage(drive);
    if( storage.isValid() && storage.isReady() ) {
        qDebug() << "Name:" << storage.name();
        qDebug() << "Used:" << (storage.bytesTotal()-storage.bytesAvailable()) * 1.0 / GB << "GB";
        qDebug() << "Free:" << storage.bytesAvailable() * 1.0 / GB << "GB";
        qDebug() << "Total:" << storage.bytesTotal() * 1.0 / GB << "GB";
    }
}


...
PrintVolumeInfo("C:");
...

 

실행 결과는 다음과 같다.

QStorageInfo.png

TAG •