我正在使用 Qt 并且想要一种独立于平台的方式来获取可用的可用磁盘空间.
我知道在 Linux 中我可以使用 statfs,而在 Windows 中我可以使用 GetDiskFreeSpaceEx().我知道 boost 有一种方法,boost::filesystem::space(Path const & p).
但我不想要那些.我在 Qt 中,并希望以 Qt 友好的方式进行.
我看了QDir、QFile、QFileInfo——什么都没有!
我知道这是一个很老的话题,但仍然有人觉得它很有用.
自 QT 5.4 起,QSystemStorageInfo 已停止使用,取而代之的是一个新类 QStorageInfo,它使整个任务变得非常简单并且是跨平台的.
QStorageInfo storage = QStorageInfo::root();qDebug() <<storage.rootPath();如果 (storage.isReadOnly())qDebug() <<是只读的:"<<storage.isReadOnly();qDebug() <<姓名:"<<存储名称();qDebug() <<文件系统类型:"<<storage.fileSystemType();qDebug() <<尺寸:"<<storage.bytesTotal()/1000/1000 <<"MB";qDebug() <<可用大小:"<<storage.bytesAvailable()/1000/1000 <<"MB";<块引用>
已从QT 5.5 文档
中的示例中复制代码I'm using Qt and want a platform-independent way of getting the available free disk space.
I know in Linux I can use statfs and in Windows I can use GetDiskFreeSpaceEx(). I know boost has a way, boost::filesystem::space(Path const & p).
But I don't want those. I'm in Qt and would like to do it in a Qt-friendly way.
I looked at QDir, QFile, QFileInfo -- nothing!
I know It's quite old topic but somebody can still find it useful.
Since QT 5.4 the QSystemStorageInfo is discontinued, instead there is a new class QStorageInfo that makes the whole task really simple and it's cross-platform.
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()/1000/1000 << "MB";
qDebug() << "availableSize:" << storage.bytesAvailable()/1000/1000 << "MB";
Code has been copied from the example in QT 5.5 docs
这篇关于如何确定Qt驱动器上有多少可用空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何在 C++ 中读取和操作 CSV 文件数据?How can I read and manipulate CSV file data in C++?(如何在 C++ 中读取和操作 CSV 文件数据?)
在 C++ 中,为什么我不能像这样编写 for() 循环:In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,为什么我不能像这样编写 for() 循环: for(
OpenMP 如何处理嵌套循环?How does OpenMP handle nested loops?(OpenMP 如何处理嵌套循环?)
在循环 C++ 中重用线程Reusing thread in loop c++(在循环 C++ 中重用线程)
需要精确的线程睡眠.最大 1ms 误差Precise thread sleep needed. Max 1ms error(需要精确的线程睡眠.最大 1ms 误差)
是否需要“do {...} while ()"?环形?Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?环形?)