Answer the question
In order to leave comments, you need to log in
How to find out disk size in qt creator?
Tried on winapi, but nothing comes out. Is there an easier implementation of getting the size of, for example, a flash drive on the "E:\" drive?
Code trying to get the size
void MainWindow::on_pushButton_clicked()
{
QString file_name = QFileDialog::getExistingDirectory();
ui->usbpath->setText(file_name);
string pathfile = file_name.toUtf8().constData();
wstring stemp = s2ws(pathfile);
LPCTSTR lpDirectoryName = stemp.c_str();
PULARGE_INTEGER lpFreeBytesAvailable;
PULARGE_INTEGER lpTotalNumberOfBytes;
PULARGE_INTEGER lpTotalNumberOfFreeBytes;
LPCTSTR pat = lpDirectoryName;
if(GetDiskFreeSpaceEx(pat,lpFreeBytesAvailable,lpTotalNumberOfBytes,lpTotalNumberOfFreeBytes))
{
cout << lpFreeBytesAvailable << endl;
}
}
Answer the question
In order to leave comments, you need to log in
QStorageInfo storage("e:/");
qDebug() << "name:" << storage.name();
qDebug() << "fileSystemType:" << storage.fileSystemType();
qDebug() << "size:" << storage.bytesTotal()/1000/1000 << "MB";
qDebug() << "availableSize:" << storage.bytesAvailable()/1000/1000 << "MB";
#include <QStorageInfo>
#include <QDebug>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question