QStorageInfo Class
現在マウントされているストレージとドライブに関する情報を提供する。詳細...
ヘッダ | #include <QStorageInfo> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
- 継承メンバを含む全メンバ一覧
- QStorageInfoは、Input/OutputおよびNetworkingと Implicitly Shared Classに属しています。
このクラスは等価比較可能です。
パブリック関数
QStorageInfo() | |
QStorageInfo(const QDir &dir) | |
QStorageInfo(const QString &path) | |
QStorageInfo(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) |
QStorageInfo & | operator=(QStorageInfo &&other) |
QStorageInfo & | operator=(const QStorageInfo &other) |
静的パブリック・メンバー
QList<QStorageInfo> | mountedVolumes() |
QStorageInfo | root() |
関連非会員
bool | operator!=(const QStorageInfo &lhs, const QStorageInfo &rhs) |
bool | operator==(const QStorageInfo &lhs, const QStorageInfo &rhs) |
詳細説明
ボリュームの領域、マウントポイント、ラベル、ファイルシステム名に関する情報を取得できるようにします。
QStorageInfo のインスタンスを作成するには、ボリュームのマウント・ポイントへのパスをコンストラクタのパラメータとして渡すか、setPath() メソッドを使用して設定します。staticmountedVolumes() メソッドを使用すると、マウントされているすべてのファイルシステムのリストを取得できます。
QStorageInfo は、取得した情報を常にキャッシュしますが、refresh() を呼び出してキャッシュを無効にできます。
以下の例は、システムのルート・ボリュームに関する最も一般的な情報を取得し、その情報を表示します。
QStorageInfostorage=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::QStorageInfo()
空の QStorageInfo オブジェクトを構築します。
デフォルトのコンストラクタで作成されたオブジェクトは無効であるため、使用できません。
setPath(),isReady(),isValid()も参照してください 。
[explicit]
QStorageInfo::QStorageInfo(const QDir &dir)
dir フォルダを含むボリュームに関する情報を提供する新しい QStorageInfo オブジェクトを構築します。
[explicit]
QStorageInfo::QStorageInfo(const QString &path)
path にマウントされたボリュームに関する情報を提供する新しい QStorageInfo オブジェクトを構築します。
ディレクトリまたはファイルを渡すと、QStorageInfo オブジェクトは、そのディレクトリまたはファイルがあるボリュームを参照します。作成されたオブジェクトが正しいかどうかは、isValid() メソッドを使用して確認できます。
次の例では、アプリケーションが置かれているボリュームを取得する方法を示します。ボリュームが準備できており、有効であることを常に確認することをお勧めします。
QStorageInfo storage(qApp->applicationDirPath()); if (storage.isValid() && storage.isReady()) { // ... }
setPath()も参照 。
QStorageInfo::QStorageInfo(const QStorageInfo &other)
other QStorageInfo オブジェクトのコピーである新しい QStorageInfo オブジェクトを構築します。
[noexcept]
QStorageInfo::~QStorageInfo()
QStorageInfo オブジェクトを破棄し、そのリソースを解放する。
int QStorageInfo::blockSize() const
このファイルシステムに最適な転送ブロックサイズを返す。
QStorageInfo がサイズを決定できなかった場合、またはQStorageInfo オブジェクトが有効でない場合は -1 を返します。
qint64 QStorageInfo::bytesAvailable() const
現在のユーザーが使用可能なサイズ(バイト単位)を返します。ユーザがルート・ユーザまたはシステム管理者である場合は、使用可能な合計サイズが返される。
このサイズは、bytesFree() 関数によって返されるフリー・サイズ以下である可能性がある。
QStorageInfo オブジェクトが有効でない場合は -1 を返す。
bytesTotal() およびbytesFree()も参照のこと 。
qint64 QStorageInfo::bytesFree() const
ボリューム内の空きバイト数を返す。ファイルシステムにクォータがある場合、この値はbytesAvailable() が返す値よりも大きくなる可能性があることに注意。
QStorageInfo オブジェクトが有効でない場合は -1 を返します。
bytesTotal() およびbytesAvailable()も参照 。
qint64 QStorageInfo::bytesTotal() const
ボリュームの合計サイズをバイト単位で返します。
QStorageInfo オブジェクトが有効でない場合は -1 を返す。
bytesFree() およびbytesAvailable()も参照 。
QByteArray QStorageInfo::device() const
このボリュームのデバイスを返します。
たとえば、Unixファイルシステム(macOSを含む)では、ローカルストレージの/dev/sda0
のようなdevpathを返す。Windowsでは、ローカル・ストレージの\\\\?\\
で始まるUNCパスが返される(言い換えれば、ボリュームのGUID)。
rootPath() およびsubvolume()も参照のこと 。
QString QStorageInfo::displayName() const
ボリュームの名前があればその名前を、なければルート・パスを返します。
QByteArray QStorageInfo::fileSystemType() const
ファイルシステムのタイプ名を返す。
これはプラットフォームに依存する関数であり、ファイルシステム名はオペレーティング・システムによって異なることがある。例えば、Windows ファイルシステムではNTFS
という名前になり、Linux ではntfs-3g
またはfuseblk
という名前になります。
name()も参照のこと 。
bool QStorageInfo::isReadOnly() const
現在のファイルシステムが書き込みから保護されている場合はtrueを返し、そうでない場合はfalseを返します。
bool QStorageInfo::isReady() const
現在のファイルシステムが動作可能であればtrueを返し、そうでなければfalseを返す。例えば、CDボリュームが挿入されていない場合はfalseが返される。
fileSystemType()、name()、bytesTotal()、bytesFree()、bytesAvailable() は、ボリュームの準備が整うまで無効なデータを返すことに注意。
isValid()も参照 。
bool QStorageInfo::isRoot() const
このQStorageInfo がシステム・ルート・ボリュームを表している場合は true、そうでない場合は false を返す。
Unixファイルシステムでは、ルート・ボリュームは/
にマウントされたボリュームです。Windows では、ルート・ボリュームは OS がインストールされているボリュームです。
root()も参照してください 。
bool QStorageInfo::isValid() const
rootPath で指定されたQStorageInfo が存在し、正しくマウントされていれば true を返す。
isReady()も参照のこと 。
[static]
QList<QStorageInfo> QStorageInfo::mountedVolumes()
現在マウントされているファイルシステムのリストに対応するQStorageInfo オブジェクトのリストを返す。
Windows では、マイコンピュータフォルダに表示されているドライブを返します。Unix オペレーティング・システムでは、マウントされているすべてのファイルシステムのリストを返します(擬似ファイルシステムを除く)。
デフォルトでは、現在マウントされているすべてのファイルシステムを返します。
この例では、読み取り専用のファイルシステムをスキップして、利用可能なすべてのファイルシステムを取得する方法を示している。
foreach (const QStorageInfo &storage, QStorageInfo::mountedVolumes()) { if (storage.isValid() && storage.isReady()) { if (!storage.isReadOnly()) { // ... } } }
root()も参照 。
QString QStorageInfo::name() const
通常label
と呼ばれるファイルシステムの、人間が読める名前を返す。
すべてのファイルシステムがこの機能をサポートしているわけではない。この場合、このメソッドが返す値は空になる可能性があります。ファイルシステムがラベルをサポートしていない場合、またはラベルが設定されていない場合は、空の文字列が返されます。
Linuxでは、ボリュームのラベルを取得するには、udev
がシステムに存在する必要があります。
fileSystemType()も参照のこと 。
void QStorageInfo::refresh()
QStorageInfo の内部キャッシュをリセットする。
QStorageInfo QStorageInfo は、オブジェクト構築時や () メソッド呼び出し時に情報を取得します。ストレージ情報を更新するには、この関数を呼び出して手動でキャッシュをリセットする必要があります。setPath
[static]
QStorageInfo QStorageInfo::root()
システム・ルート・ボリュームを表すQStorageInfo オブジェクトを返します。
Unixシステムではルート('/')ボリュームを返し、Windowsではオペレーティング・システムがインストールされているボリュームを返す。
isRoot()も参照 。
QString QStorageInfo::rootPath() const
このQStorageInfo オブジェクトが表すファイルシステムのマウント・ポイントを返します。
Windows では、ボリュームがディレクトリにマウントされていない場合にボリューム文字を返します。
rootPath() が返す値は、ボリュームの実際のマウント・ポイントであり、コンストラクタやsetPath() メソッドに渡された値とは異なる場合があることに注意してください。たとえば、システムにルートボリュームしかなく、setPath() に '/directory' を渡した場合、このメソッドは '/' を返します。
void QStorageInfo::setPath(const QString &path)
path がマウントされているファイルシステムにこのQStorageInfo オブジェクトを設定します。
path ファイルシステムのルートパス、ディレクトリ、またはファイルシステム内のファイルのいずれかを指定します。
rootPath()も参照 。
QByteArray QStorageInfo::subvolume() const
このボリュームのサブボリューム名を返します。
ファイルシステムの種類によっては、1つのデバイス内に複数のサブボリュームを持つことができ、それらは異なるパスにマウントされることがあります(Unixの'bind'マウントやBtrfsファイルシステムのサブボリュームなど)。サブボリュームが検出された場合、その名前がこの関数によって返されます。サブボリューム名のフォーマットは、各ファイルシステムタイプに固有です。
このボリュームがより大きなファイルシステムのサブボリュームからマウントされていない場合、またはサブボリュームを検出できなかった場合、この関数は空のバイト配列を返します。
device()も参照 。
[noexcept]
void QStorageInfo::swap(QStorageInfo &other)
このボリューム情報をother と交換する。この操作は非常に高速で、失敗することはない。
[noexcept]
QStorageInfo &QStorageInfo::operator=(QStorageInfo &&other)
このQStorageInfo インスタンスにother を割り当てる。
QStorageInfo &QStorageInfo::operator=(const QStorageInfo &other)
QStorageInfo オブジェクトother のコピーを作成し、このQStorageInfo オブジェクトに割り当てる。
関連する非会員
[noexcept]
bool operator!=(const QStorageInfo &lhs, const QStorageInfo &rhs)
QStorageInfo オブジェクトlhs がQStorageInfo オブジェクトrhs と異なるドライブまたはボリュームを参照している場合はtrue
を返し、そうでない場合はfalse
を返す。
[noexcept]
bool operator==(const QStorageInfo &lhs, const QStorageInfo &rhs)
QStorageInfo オブジェクトlhs がQStorageInfo オブジェクトrhs と同じドライブまたはボリュームを参照している場合はtrue
を返し、そうでない場合はfalse
を返す。
2つの無効なQStorageInfo オブジェクトを比較した結果は、常に正であることに注意してください。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.