D
D
dimoSSHka2019-06-08 21:18:01
C++ / C#
dimoSSHka, 2019-06-08 21:18:01

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;
       }



}

Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SerJook, 2019-06-08
@dimoSSHka

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";

Well, at the top, do not forget to add
#include <QStorageInfo>
#include <QDebug>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question