QQmlDataBlob Class

The QQmlDataBlob encapsulates a data request that can be issued to a QQmlTypeLoader. \internal. More...

Header: #include <QQmlDataBlob>

Public Types

enum Status { Null, Loading, WaitingForDependencies, Complete, Error }
enum Type { QmlFile, JavaScriptFile, QmldirFile }

Public Functions

QQmlDataBlob(const QUrl &url, Type type, QQmlTypeLoader *manager)
~QQmlDataBlob()
QList<QQmlError> errors() const
QUrl finalUrl() const
QString finalUrlString() const
bool isComplete() const
bool isCompleteOrError() const
bool isError() const
bool isLoading() const
bool isNull() const
bool isWaiting() const
qreal progress() const
void startLoading()
Status status() const
Type type() const
QUrl url() const

Protected Functions

void addDependency(QQmlDataBlob *blob)
virtual void allDependenciesDone()
virtual void completed()
virtual void dependencyComplete(QQmlDataBlob *blob)
virtual void dependencyError(QQmlDataBlob *blob)
virtual void done()
virtual void downloadProgressChanged(qreal progress)
virtual void networkError(QNetworkReply::NetworkError networkError)
void setError(const QQmlError &errors)
void setError(const QList<QQmlError> &errors)

Detailed Description

QQmlDataBlob's are loaded by a QQmlTypeLoader. The user creates the QQmlDataBlob and then calls QQmlTypeLoader::load() or QQmlTypeLoader::loadWithStaticData() to load it. The QQmlTypeLoader invokes callbacks on the QQmlDataBlob as data becomes available.

Member Type Documentation

enum QQmlDataBlob::Status

This enum describes the status of the data blob.

ConstantValueDescription
QQmlDataBlob::Null0The blob has not yet been loaded by a QQmlTypeLoader
QQmlDataBlob::Loading1The blob is loading network data. The QQmlDataBlob::setData() callback has not yet been invoked or has not yet returned.
QQmlDataBlob::WaitingForDependencies2The blob is waiting for dependencies to be done before continuing. This status only occurs after the QQmlDataBlob::setData() callback has been made, and when the blob has outstanding dependencies.
QQmlDataBlob::Complete4The blob's data has been loaded and all dependencies are done.
QQmlDataBlob::Error5An error has been set on this blob.

enum QQmlDataBlob::Type

This enum describes the type of the data blob.

ConstantValueDescription
QQmlDataBlob::QmlFileQQmlAbstractUrlInterceptor::QmlFileThis is a QQmlTypeData
QQmlDataBlob::JavaScriptFileQQmlAbstractUrlInterceptor::JavaScriptFileThis is a QQmlScriptData
QQmlDataBlob::QmldirFileQQmlAbstractUrlInterceptor::QmldirFileThis is a QQmlQmldirData

Member Function Documentation

QQmlDataBlob::QQmlDataBlob(const QUrl &url, Type type, QQmlTypeLoader *manager)

Create a new QQmlDataBlob for url and of the provided type.

[noexcept] QQmlDataBlob::~QQmlDataBlob()

\internal

[protected] void QQmlDataBlob::addDependency(QQmlDataBlob *blob)

Wait for blob to become complete or to error. If blob is already complete or in error, or this blob is already complete, this has no effect.

The setError() method may only be called from within a QQmlDataBlob callback.

[virtual protected] void QQmlDataBlob::allDependenciesDone()

Called when all blobs waited for have completed. This occurs regardless of whether they are in error, or complete state.

The default implementation does nothing.

[virtual protected] void QQmlDataBlob::completed()

Invoked on the main thread sometime after done() was called on the load thread.

You cannot modify the blobs state at all in this callback and cannot depend on the order or timeliness of these callbacks. Implementors should use this callback to notify dependencies on the main thread that the blob is done and not a lot else.

This callback is only invoked if an asynchronous load for this blob is made. An asynchronous load is one in which the Asynchronous mode is specified explicitly, or one that is implicitly delayed due to a network operation.

The default implementation does nothing.

[virtual protected] void QQmlDataBlob::dependencyComplete(QQmlDataBlob *blob)

Called if blob, which was previously waited for, has completed.

The default implementation does nothing.

[virtual protected] void QQmlDataBlob::dependencyError(QQmlDataBlob *blob)

Called if blob, which was previously waited for, has an error.

The default implementation does nothing.

[virtual protected] void QQmlDataBlob::done()

Invoked once data has either been received or a network error occurred, and all dependencies are complete.

You can set an error in this method, but you cannot add new dependencies. Implementors should use this callback to finalize processing of data.

The default implementation does nothing.

XXX Rename processData() or some such to avoid confusion between done() (processing thread) and completed() (main thread)

[virtual protected] void QQmlDataBlob::downloadProgressChanged(qreal progress)

Called when the download progress of this blob changes. progress goes from 0 to 1.

This callback is only invoked if an asynchronous load for this blob is made. An asynchronous load is one in which the Asynchronous mode is specified explicitly, or one that is implicitly delayed due to a network operation.

The default implementation does nothing.

QList<QQmlError> QQmlDataBlob::errors() const

Return the errors on this blob.

May only be called from the load thread, or after the blob isCompleteOrError().

QUrl QQmlDataBlob::finalUrl() const

Returns the logical URL to be used for resolving further URLs referred to in the code.

This is the blob url passed to the constructor. If a URL interceptor rewrites the URL, this one stays the same. If a network redirect happens while fetching the data, this url is updated to reflect the new location. Therefore, if both an interception and a redirection happen, the final url will indirectly incorporate the result of the interception, potentially breaking further lookups.

See also url().

QString QQmlDataBlob::finalUrlString() const

Returns the finalUrl() as a string.

bool QQmlDataBlob::isComplete() const

Returns true if the status is Complete.

bool QQmlDataBlob::isCompleteOrError() const

Returns true if the status is Complete or Error.

bool QQmlDataBlob::isError() const

Returns true if the status is Error.

bool QQmlDataBlob::isLoading() const

Returns true if the status is Loading.

bool QQmlDataBlob::isNull() const

Returns true if the status is Null.

bool QQmlDataBlob::isWaiting() const

Returns true if the status is WaitingForDependencies.

[virtual protected] void QQmlDataBlob::networkError(QNetworkReply::NetworkError networkError)

Invoked if there is a network error while fetching this blob.

The default implementation sets an appropriate QQmlError.

qreal QQmlDataBlob::progress() const

Returns the data download progress from 0 to 1.

[protected] void QQmlDataBlob::setError(const QQmlError &errors)

Mark this blob as having errors.

All outstanding dependencies will be cancelled. Requests to add new dependencies will be ignored. Entry into the Error state is irreversable.

The setError() method may only be called from within a QQmlDataBlob callback.

See also isError().

[protected] void QQmlDataBlob::setError(const QList<QQmlError> &errors)

This is an overloaded function.

void QQmlDataBlob::startLoading()

Must be called before loading can occur.

Status QQmlDataBlob::status() const

Returns the blob's status.

Type QQmlDataBlob::type() const

Returns the type provided to the constructor.

QUrl QQmlDataBlob::url() const

Returns the physical url of the data. Initially this is the same as finalUrl(), but if a URL interceptor is set, it will work on this URL and leave finalUrl() alone.

See also finalUrl().