QStorageInfo 类【官翻】

QStorageInfo 类

提供有关当前安装的存储和驱动器的信息。

Header:#include < QStorageInfo >
qmake:QT += core
Inherits:
Inherited By:

详述

允许检索有关卷的空间,其安装点,标签和文件系统名称的信息。

可以通过将路径作为构造函数参数传递到卷的安装点来创建QStorageInfo的实例,也可以使用setPath()方法对其进行设置。 静态mountVolumes()方法可用于获取所有已挂载文件系统的列表。

QStorageInfo总是缓存检索到的信息,但是您可以调用refresh()使缓存无效。

以下示例检索有关系统根卷的最常用信息,并打印有关它的信息。

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

公共函数

  1. QStorageInfo(const QStorageInfo &other)

  2. QStorageInfo(const QDir &dir)

  3. QStorageInfo(const QString &path) 构造一个新的QStorageInfo对象,提供有关path上的卷的信息。
    如果传递目录或文件,则QStorageInfo对象将引用该目录或文件所在的卷。 您可以使用isValid()方法检查创建的对象是否正确。
    以下示例显示如何获取应用程序所在的卷。 建议始终检查该卷是否已准备好并有效。

         QStorageInfo storage(qApp->applicationDirPath());
         if (storage.isValid() && storage.isReady()) {
             // ...
         }
    
  4. QStorageInfo()

  5. QStorageInfo & operator=(QStorageInfo &&other)

  6. QStorageInfo & operator=(const QStorageInfo &other)

  7. ~QStorageInfo()

  8. int blockSize() const

  9. qint64 bytesAvailable() const

  10. qint64 bytesFree() const

  11. qint64 bytesTotal() const

  12. QByteArray device() const

  13. QString displayName() const

  14. QByteArray fileSystemType() const

  15. bool isReadOnly() const

  16. bool isReady() const

  17. bool isRoot() const

  18. bool isValid() const

  19. QString name() const

  20. void refresh()

  21. QString rootPath() const

  22. void setPath(const QString &path)

  23. QByteArray subvolume() const

  24. void swap(QStorageInfo &other)

静态公共函数

  1. QList< QStorageInfo > mountedVolumes() 返回与当前安装的文件系统列表相对应的QStorageInfo对象的列表。
    在Windows上,这将返回“我的电脑”文件夹中可见的驱动器。 在Unix操作系统上,它返回所有已挂载文件系统的列表(伪文件系统除外)。
    默认情况下返回所有当前挂载的文件系统。
    该示例显示如何检索所有可用的文件系统,跳过只读文件系统。

         foreach (const QStorageInfo &storage, QStorageInfo::mountedVolumes()) {
             if (storage.isValid() && storage.isReady()) {
                 if (!storage.isReadOnly()) {
                     // ...
                 }
             }
         }
    
  2. QStorageInfo root()

相关非成员

  1. bool operator!=(const QStorageInfo &first, const QStorageInfo &second)
  2. bool operator==(const QStorageInfo &first, const QStorageInfo &second)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值