qt的磁盘剩余容量检测
void A::check()
{
QString rootPath = "D:/d/c/f/s/d/f/g";
if(rootPath.isEmpty())
{
return;
}
QStorageInfo storageInfo(rootPath);
qint64 freeBytes = storageInfo.bytesAvailable();
qint64 totalBytes = storageInfo.bytesTotal();
double freePercentage = (double(freeBytes) / double(totalBytes)) * 100.0;
qDebug() << "剩余空间:" << freePercentage << "%";
if (freePercentage < 1.0)
{
qDebug() << "剩余空间小于 1%。退出...";
QMessageBox::critical(nullptr, tr("磁盘空间不足"), tr("磁盘空间不足 1%"));
// QCoreApplication::quit(); // 退出程序
}
}
本文来自博客园,作者:东岸,转载请注明原文链接:https://www.cnblogs.com/donghao99/p/18234785