QQmlFileSelector Class

A class for applying a QFileSelector to QML file loading 更多...

头文件: #include <QQmlFileSelector>
qmake: QT += qml
开始支持版本: Qt 5.2
基类: QObject

公有函数

QQmlFileSelector(QQmlEngine *engine, QObject *parent = Q_NULLPTR)
~QQmlFileSelector()
QFileSelector *selector() const
void setExtraSelectors(QStringList &strings)
void setExtraSelectors(const QStringList &strings)
void setSelector(QFileSelector *selector)
  • 32 个公有函数继承自 QObject

静态公有成员

QQmlFileSelector *get(QQmlEngine *engine)
  • 10 个静态公有成员继承自 QObject

其他继承的成员

  • 1 个属性继承自 QObject
  • 1 个公有槽函数继承自 QObject
  • 2 个信号继承自 QObject
  • 1 个公有变量继承自 QObject
  • 9 个受保护的函数继承自 QObject
  • 2 个受保护的变量继承自 QObject

详细描述

A class for applying a QFileSelector to QML file loading

QQmlFileSelector will automatically apply a QFileSelector to qml file and asset paths.

It is used as follows:


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

Then you can swap out files like so:


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

In this example, main.qml will normally use Component.qml for the Component type. However on a unix platform, the unix selector will be present and the +unix/Component.qml version will be used instead. Note that this acts like swapping out Component.qml with +unix/Component.qml, so when using Component.qml you should not need to alter any paths based on which version was selected.

For example, to pass the "asset.png" file path around you would refer to it just as "asset.png" in all of main.qml, Component.qml, and +linux/Component.qml. It will be replaced with +mac/asset.png on Mac platforms in all cases.

For a list of available selectors, see QFileSelector.

Your platform may also provide additional selectors for you to use. As specified by QFileSelector, directories used for selection must start with a '+' character, so you will not accidentally trigger this feature unless you have directories with such names inside your project.

If a new QQmlFileSelector is set on the engine, the old one will be replaced. Use QQmlFileSelector::get() to query or use the existing instance.

成员函数

QQmlFileSelector::QQmlFileSelector(QQmlEngine *engine, QObject *parent = Q_NULLPTR)

Creates a new QQmlFileSelector with parent object parent, which includes its own QFileSelector. engine is the QQmlEngine you wish to apply file selectors to. It will also take ownership of the QQmlFileSelector.

QQmlFileSelector::~QQmlFileSelector()

Destroys the QQmlFileSelector object.

[static] QQmlFileSelector *QQmlFileSelector::get(QQmlEngine *engine)

Gets the QQmlFileSelector currently active on the target engine.

QFileSelector *QQmlFileSelector::selector() const

Returns the QFileSelector instance used by the QQmlFileSelector.

This function was introduced in Qt 5.7.

参见 setSelector().

void QQmlFileSelector::setExtraSelectors(QStringList &strings)

Adds extra selectors contained in strings to the current QFileSelector being used. Use this when extra selectors are all you need to avoid having to create your own QFileSelector instance.

void QQmlFileSelector::setExtraSelectors(const QStringList &strings)

Adds extra selectors contained in strings to the current QFileSelector being used. Use this when extra selectors are all you need to avoid having to create your own QFileSelector instance.

void QQmlFileSelector::setSelector(QFileSelector *selector)

Sets the QFileSelector instance for use by the QQmlFileSelector to selector. QQmlFileSelector does not take ownership of the new QFileSelector. To reset QQmlFileSelector to use its internal QFileSelector instance, call setSelector(0).

参见 selector().