Important: Please read the Qt Code of Conduct -

Displaying available storage with QStorageInfo class

  • I have an issue where I'm trying to get the free memory storage left after creating video .avi file and display it on a GUI. I'm currently using the attached method.
    After a video is created, neither bytesFree and bytesAvailable update either in debug or in the GUI; only once i reboot the computer and open the program again does it show an updated number. How do I change it so that it reflects an updated number after each recording?

        QStorageInfo storage = QStorageInfo::root();
        qint64 availableStorage_qint64 = storage.bytesFree(); //bytesFree(); bytesAvailable
        float availableStorage_float = availableStorage_qint64/(1000.0 * 1000.0 * 1000.0);
        QString availableStorageStr = " " + QString::number(availableStorage_float, 'f', 3) + "GB Available"; // actual displayed string
        ui->labelAvailableMemory->setStyleSheet("background-color: red");

  • QStorageInfo always caches the retrieved information, but you can call refresh() to invalidate the cache.

  • tnx it worked

Log in to reply