QQmlFileSelector Class

QML ファイルの読み込みにQFileSelector を適用するためのクラス。詳細...

ヘッダー #include <QQmlFileSelector>
CMake: find_package(Qt6 REQUIRED COMPONENTS Qml)
target_link_libraries(mytarget PRIVATE Qt6::Qml)
qmake: QT += qml
継承: QObject

パブリック関数

QQmlFileSelector(QQmlEngine *engine, QObject *parent = nullptr)
virtual ~QQmlFileSelector() override
QFileSelector *selector() const
void setExtraSelectors(const QStringList &strings)
void setSelector(QFileSelector *selector)

詳しい説明

QQmlFileSelector は、qml ファイルとアセットのパスにQFileSelector を自動的に適用します。

次のように使います:

QQmlEngine engine;
QQmlFileSelector* selector = new QQmlFileSelector(&engine);

このようにファイルを入れ替えることができます:

main.qml
Component.qml
asset.png
+unix/Component.qml
+mac/asset.png

この例では、main.qmlは通常ComponentタイプにComponent.qmlを使用します。しかし、unixプラットフォームでは、unixセレクタが存在し、+unix/Component.qmlバージョンが代わりに使用されます。これはComponent.qmlと+unix/Component.qmlを入れ替えたようなものなので、Component.qmlを使用する場合、どのバージョンが選択されたかに応じてパスを変更する必要はないことに注意してください。

たとえば、"asset.png "ファイルのパスを渡すには、main.qml、Component.qml、+linux/Component.qmlのすべてで "asset.png "とだけ参照します。Macプラットフォームでは、すべてのケースで+mac/asset.pngに置き換えられます。

利用可能なセレクタの一覧はQFileSelector を参照してください。

お使いのプ ラ ッ ト フ ォームで も 、 利用可能な追加のセ レ ク タ が提供 さ れ る 場合があ り ます。QFileSelector で指定されているように、セレクションに使用するディレクトリは '+' 文字で始まる必要があります。

新しい QQmlFileSelector がエンジンに設定されると、古いものは置き換えられます。

メンバー関数ドキュメント

[explicit] QQmlFileSelector::QQmlFileSelector(QQmlEngine *engine, QObject *parent = nullptr)

親オブジェクトparent を持つ新しい QQmlFileSelector を作成します。親オブジェクトは、自身のQFileSelector を含みます。engine は、ファイルセレクタを適用したいQQmlEngine です。また、QQmlFileSelector の所有権も取得します。

[override virtual noexcept] QQmlFileSelector::~QQmlFileSelector()

QQmlFileSelector オブジェクトを破棄する。

[noexcept] QFileSelector *QQmlFileSelector::selector() const

QQmlFileSelector が使用するQFileSelector インスタンスを返す。

setSelector()も参照

void QQmlFileSelector::setExtraSelectors(const QStringList &strings)

strings に含まれる追加セレクタを、現在使用中のQFileSelector に追加する。独自のQFileSelector インスタンスを作成する手間を省くために、追加のセレクタが必要な場合に使用します。

void QQmlFileSelector::setSelector(QFileSelector *selector)

QQmlFileSelector が使用するQFileSelector インスタンスをselector に設定する。QQmlFileSelector は新しいQFileSelector の所有権を取らない。QQmlFileSelector をリセットして内部のQFileSelector インスタンスを使用するには、 setSelector(nullptr) を呼び出す。

selector()も参照

© 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.