gpt4 book ai didi

c++ - 如何确定 Qt 驱动器上有多少可用空间?

转载 作者:IT老高 更新时间:2023-10-28 22:22:54 28 4
gpt4 key购买 nike

我正在使用 Qt,并且想要一种独立于平台的方式来获取可用磁盘空间。

我知道在 Linux 中我可以使用 statfs,而在 Windows 中我可以使用 GetDiskFreeSpaceEx()。我知道 boost 有一个方法,boost::filesystem::space(Path const & p)

但我不想要那些。我在 Qt 中,希望以一种对 Qt 友好的方式来做。

我看了QDirQFileQFileInfo——什么都没有!

最佳答案

我知道这是一个很老的话题,但仍然有人会发现它很有用。

自 QT 5.4 起,QSystemStorageInfo 已停用,取而代之的是一个新类 QStorageInfo,它使整个任务变得非常简单,而且它是跨平台的。

QStorageInfo storage = QStorageInfo::root();

qDebug() << storage.rootPath();
if (storage.isReadOnly())
qDebug() << "isReadOnly:" << storage.isReadOnly();

qDebug() << "name:" << storage.name();
qDebug() << "fileSystemType:" << storage.fileSystemType();
qDebug() << "size:" << storage.bytesTotal()/1024/1024 << "MB";
qDebug() << "availableSize:" << storage.bytesAvailable()/1024/1024 << "MB";

Code has been copied from the example in QT 5.5 docs

关于c++ - 如何确定 Qt 驱动器上有多少可用空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1732717/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com