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";
公共函数
-
QStorageInfo(const QStorageInfo &other)
-
QStorageInfo(const QDir &dir)
-
QStorageInfo(const QString &path) 构造一个新的QStorageInfo对象,提供有关path上的卷的信息。
如果传递目录或文件,则QStorageInfo对象将引用该目录或文件所在的卷。 您可以使用isValid()方法检查创建的对象是否正确。
以下示例显示如何获取应用程序所在的卷。 建议始终检查该卷是否已准备好并有效。QStorageInfo storage(qApp->applicationDirPath()); if (storage.isValid() && storage.isReady()) { // ... }
-
QStorageInfo()
-
QStorageInfo & operator=(QStorageInfo &&other)
-
QStorageInfo & operator=(const QStorageInfo &other)
-
~QStorageInfo()
-
int blockSize() const
-
qint64 bytesAvailable() const
-
qint64 bytesFree() const
-
qint64 bytesTotal() const
-
QByteArray device() const
-
QString displayName() const
-
QByteArray fileSystemType() const
-
bool isReadOnly() const
-
bool isReady() const
-
bool isRoot() const
-
bool isValid() const
-
QString name() const
-
void refresh()
-
QString rootPath() const
-
void setPath(const QString &path)
-
QByteArray subvolume() const
-
void swap(QStorageInfo &other)
静态公共函数
-
QList< QStorageInfo > mountedVolumes() 返回与当前安装的文件系统列表相对应的QStorageInfo对象的列表。
在Windows上,这将返回“我的电脑”文件夹中可见的驱动器。 在Unix操作系统上,它返回所有已挂载文件系统的列表(伪文件系统除外)。
默认情况下返回所有当前挂载的文件系统。
该示例显示如何检索所有可用的文件系统,跳过只读文件系统。foreach (const QStorageInfo &storage, QStorageInfo::mountedVolumes()) { if (storage.isValid() && storage.isReady()) { if (!storage.isReadOnly()) { // ... } } }
-
QStorageInfo root()
相关非成员
- bool operator!=(const QStorageInfo &first, const QStorageInfo &second)
- bool operator==(const QStorageInfo &first, const QStorageInfo &second)