QQmlTypeLoader Class

The QQmlTypeLoader class abstracts loading files and their dependencies over the network. \internal. More...

Header: #include <QQmlTypeLoader>

Public Functions

QQmlTypeLoader(QQmlEngine *engine)
~QQmlTypeLoader()
QString absoluteFilePath(const QString &path)
void clearCache()
bool directoryExists(const QString &path)
QQmlEngine *engine() const
QQmlRefPointer<QQmlQmldirData> getQmldir(const QUrl &url)
QQmlRefPointer<QQmlScriptBlob> getScript(const QUrl &unNormalizedUrl)
QQmlRefPointer<QQmlTypeData> getType(const QUrl &unNormalizedUrl, Mode mode = PreferSynchronous)
QQmlRefPointer<QQmlTypeData> getType(const QByteArray &data, const QUrl &url, Mode mode = PreferSynchronous)
void load(QQmlDataBlob *blob, Mode mode = PreferSynchronous)
void loadWithStaticData(QQmlDataBlob *blob, const QByteArray &data, Mode mode = PreferSynchronous)
const QQmlTypeLoaderQmldirContent qmldirContent(const QString &filePathIn)

Detailed Description

The QQmlTypeLoader class is provided for the exclusive use of the QQmlTypeLoader class.

Clients create QQmlDataBlob instances and submit them to the QQmlTypeLoader class through the QQmlTypeLoader::load() or QQmlTypeLoader::loadWithStaticData() methods. The loader then fetches the data over the network or from the local file system in an efficient way. QQmlDataBlob is an abstract class, so should always be specialized.

Once data is received, the QQmlDataBlob::dataReceived() method is invoked on the blob. The derived class should use this callback to process the received data. Processing of the data can result in an error being set (QQmlDataBlob::setError()), or one or more dependencies being created (QQmlDataBlob::addDependency()). Dependencies are other QQmlDataBlob's that are required before processing can fully complete.

To complete processing, the QQmlDataBlob::done() callback is invoked. done() is called when one of these three preconditions are met.

  1. The QQmlDataBlob has no dependencies.
  2. The QQmlDataBlob has an error set.
  3. All the QQmlDataBlob's dependencies are themselves "done()".

Thus QQmlDataBlob::done() will always eventually be called, even if the blob has an error set.

Member Function Documentation

QQmlTypeLoader::QQmlTypeLoader(QQmlEngine *engine)

Constructs a new type loader that uses the given engine.

[noexcept] QQmlTypeLoader::~QQmlTypeLoader()

Destroys the type loader, first clearing the cache of any information about loaded files.

QString QQmlTypeLoader::absoluteFilePath(const QString &path)

Returns the absolute filename of path via a directory cache. Returns a empty string if the path does not exist.

Why a directory cache? QML checks for files in many paths with invalid directories. By caching whether a directory exists we avoid many stats. We also cache the files' existence in the directory, for the same reason.

void QQmlTypeLoader::clearCache()

Clears cached information about loaded files, including any type data, scripts and qmldir information.

bool QQmlTypeLoader::directoryExists(const QString &path)

Returns true if the path is a directory via a directory cache. Cache is shared with absoluteFilePath().

QQmlEngine *QQmlTypeLoader::engine() const

Return the QQmlEngine associated with this loader

QQmlRefPointer<QQmlQmldirData> QQmlTypeLoader::getQmldir(const QUrl &url)

Returns a QQmlQmldirData for url. The QQmlQmldirData may be cached.

QQmlRefPointer<QQmlScriptBlob> QQmlTypeLoader::getScript(const QUrl &unNormalizedUrl)

Return a QQmlScriptBlob for url. The QQmlScriptData may be cached.

QQmlRefPointer<QQmlTypeData> QQmlTypeLoader::getType(const QUrl &unNormalizedUrl, Mode mode = PreferSynchronous)

Returns a QQmlTypeData for the specified url. The QQmlTypeData may be cached.

QQmlRefPointer<QQmlTypeData> QQmlTypeLoader::getType(const QByteArray &data, const QUrl &url, Mode mode = PreferSynchronous)

Returns a QQmlTypeData for the given data with the provided base url. The QQmlTypeData will not be cached.

void QQmlTypeLoader::load(QQmlDataBlob *blob, Mode mode = PreferSynchronous)

Load the provided blob from the network or filesystem.

The loader must be locked.

void QQmlTypeLoader::loadWithStaticData(QQmlDataBlob *blob, const QByteArray &data, Mode mode = PreferSynchronous)

Load the provided blob with data. The blob's URL is not used by the data loader in this case.

The loader must be locked.

const QQmlTypeLoaderQmldirContent QQmlTypeLoader::qmldirContent(const QString &filePathIn)

Return a QQmlTypeLoaderQmldirContent for absoluteFilePath. The QQmlTypeLoaderQmldirContent may be cached.

filePath is a local file path.

It can also be a remote path for a remote directory import, but it will have been cached by now in this case.