Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QQmlTypeLoader Class Reference

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

#include <qqmltypeloader_p.h>

+ Collaboration diagram for QQmlTypeLoader:

Classes

class  Blob
 

Public Types

enum  Mode { PreferSynchronous , Asynchronous , Synchronous }
 
using ChecksumCache = QHash<quintptr, QByteArray>
 

Public Member Functions

 QQmlTypeLoader (QQmlEngine *)
 Constructs a new type loader that uses the given engine.
 
 ~QQmlTypeLoader ()
 Destroys the type loader, first clearing the cache of any information about loaded files.
 
QQmlImportDatabaseimportDatabase () const
 
ChecksumCachechecksumCache ()
 
const ChecksumCachechecksumCache () const
 
QQmlRefPointer< QQmlTypeDatagetType (const QUrl &unNormalizedUrl, Mode mode=PreferSynchronous)
 Returns a QQmlTypeData for the specified url.
 
QQmlRefPointer< QQmlTypeDatagetType (const QByteArray &, const QUrl &url, Mode mode=PreferSynchronous)
 Returns a QQmlTypeData for the given data with the provided base url.
 
void injectScript (const QUrl &relativeUrl, const QV4::Value &value)
 
QQmlRefPointer< QQmlScriptBlobinjectedScript (const QUrl &relativeUrl)
 
QQmlRefPointer< QQmlScriptBlobgetScript (const QUrl &unNormalizedUrl)
 Return a QQmlScriptBlob for url.
 
QQmlRefPointer< QQmlQmldirDatagetQmldir (const QUrl &)
 Returns a QQmlQmldirData for url.
 
QString absoluteFilePath (const QString &path)
 Returns the absolute filename of path via a directory cache.
 
bool fileExists (const QString &path, const QString &file)
 
bool directoryExists (const QString &path)
 Returns true if the path is a directory via a directory cache.
 
const QQmlTypeLoaderQmldirContent qmldirContent (const QString &filePath)
 Return a QQmlTypeLoaderQmldirContent for absoluteFilePath.
 
void setQmldirContent (const QString &filePath, const QString &content)
 
void clearCache ()
 Clears cached information about loaded files, including any type data, scripts and qmldir information.
 
void trimCache ()
 
bool isTypeLoaded (const QUrl &url) const
 
bool isScriptLoaded (const QUrl &url) const
 
void lock ()
 
void unlock ()
 
void load (QQmlDataBlob *, Mode=PreferSynchronous)
 Load the provided blob from the network or filesystem.
 
void loadWithStaticData (QQmlDataBlob *, const QByteArray &, Mode=PreferSynchronous)
 Load the provided blob with data.
 
void loadWithCachedUnit (QQmlDataBlob *blob, const QQmlPrivate::CachedQmlUnit *unit, Mode mode=PreferSynchronous)
 
QQmlEngineengine () const
 Return the QQmlEngine associated with this loader.
 
void initializeEngine (QQmlEngineExtensionInterface *, const char *)
 
void initializeEngine (QQmlExtensionInterface *, const char *)
 
void invalidate ()
 
quintptr profiler () const
 
void setProfiler (quintptr)
 

Static Public Member Functions

template<typename Engine , typename EnginePrivate = QQmlEnginePrivate, typename = std::enable_if_t<std::is_same_v<Engine, QQmlEngine>>>
static QQmlTypeLoaderget (Engine *engine)
 
template<typename Engine , typename = std::enable_if_t<std::is_same_v<Engine, QQmlEnginePrivate>>>
static QQmlTypeLoaderget (Engine *engine)
 
static QUrl normalize (const QUrl &unNormalizedUrl)
 

Friends

class QQmlDataBlob
 
class QQmlTypeLoaderThread
 
struct PlainLoader
 
struct CachedLoader
 
struct StaticLoader
 

Detailed Description

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

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.

\list 1

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

Definition at line 42 of file qqmltypeloader_p.h.

Member Typedef Documentation

◆ ChecksumCache

Member Enumeration Documentation

◆ Mode

Enumerator
PreferSynchronous 
Asynchronous 
Synchronous 

Definition at line 47 of file qqmltypeloader_p.h.

Constructor & Destructor Documentation

◆ QQmlTypeLoader()

QQmlTypeLoader::QQmlTypeLoader ( QQmlEngine * engine)

Constructs a new type loader that uses the given engine.

Definition at line 907 of file qqmltypeloader.cpp.

◆ ~QQmlTypeLoader()

QQmlTypeLoader::~QQmlTypeLoader ( )

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

Definition at line 919 of file qqmltypeloader.cpp.

References clearCache(), and invalidate().

+ Here is the call graph for this function:

Member Function Documentation

◆ absoluteFilePath()

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.

Definition at line 1093 of file qqmltypeloader.cpp.

References QFileInfo::absoluteFilePath(), absoluteFilePath(), QString::at(), Qt::CaseInsensitive, QCache< Key, T >::contains(), QDir::exists(), QFile::exists(), fileName, QCache< Key, T >::insert(), QFileInfo::isFile(), QCache< Key, T >::object(), QString::size(), and QQmlFile::urlToLocalFileOrQrc().

Referenced by absoluteFilePath(), and QQmlImports::addFileImport().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checksumCache() [1/2]

ChecksumCache * QQmlTypeLoader::checksumCache ( )
inline

Definition at line 144 of file qqmltypeloader_p.h.

◆ checksumCache() [2/2]

const ChecksumCache * QQmlTypeLoader::checksumCache ( ) const
inline

Definition at line 145 of file qqmltypeloader_p.h.

◆ clearCache()

void QQmlTypeLoader::clearCache ( )

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

Definition at line 1329 of file qqmltypeloader.cpp.

References QHash< Key, T >::begin(), QStringHash< T >::clear(), QHash< Key, T >::clear(), QCache< Key, T >::clear(), QQmlThread::discardMessages(), QHash< Key, T >::end(), iter, qDeleteAll(), and TYPELOADER_MINIMUM_TRIM_THRESHOLD.

Referenced by ~QQmlTypeLoader().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ directoryExists()

bool QQmlTypeLoader::directoryExists ( const QString & path)

Returns true if the path is a directory via a directory cache.

Cache is shared with absoluteFilePath().

Definition at line 1218 of file qqmltypeloader.cpp.

References QCache< Key, T >::contains(), QDir::exists(), QFileInfo::exists(), files, QCache< Key, T >::insert(), QFileInfo::isDir(), and QCache< Key, T >::object().

Referenced by QQmlImports::addFileImport().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ engine()

QQmlEngine * QQmlTypeLoader::engine ( ) const

Return the QQmlEngine associated with this loader.

Definition at line 350 of file qqmltypeloader.cpp.

Referenced by QQmlDataBlob::QQmlDataBlob(), QQmlImports::addFileImport(), importDatabase(), initializeEngine(), and initializeEngine().

+ Here is the caller graph for this function:

◆ fileExists()

bool QQmlTypeLoader::fileExists ( const QString & path,
const QString & file )

Definition at line 1154 of file qqmltypeloader.cpp.

References Qt::CaseInsensitive, QCache< Key, T >::contains(), file, QCache< Key, T >::insert(), QCache< Key, T >::object(), Q_ASSERT, and QQmlFile::urlToLocalFileOrQrc().

Referenced by QQmlImportInstance::resolveType().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get() [1/2]

template<typename Engine , typename EnginePrivate = QQmlEnginePrivate, typename = std::enable_if_t<std::is_same_v<Engine, QQmlEngine>>>
static QQmlTypeLoader * QQmlTypeLoader::get ( Engine * engine)
inlinestatic

Definition at line 130 of file qqmltypeloader_p.h.

References engine, and get().

Referenced by QQmlPropertyCacheCreator< ObjectContainer >::createMetaObject(), QQmlCustomParser::evaluateEnum(), QV4::QQmlContextWrapper::getPropertyAndBase(), QQmlContext::importedScript(), QQmlPropertyPrivate::initProperty(), QQmlPropertyCacheCreator< ObjectContainer >::propertyCacheForObject(), QQmlCustomParser::resolveType(), and QV4::QQmlTypeWrapper::virtualGet().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get() [2/2]

template<typename Engine , typename = std::enable_if_t<std::is_same_v<Engine, QQmlEnginePrivate>>>
static QQmlTypeLoader * QQmlTypeLoader::get ( Engine * engine)
inlinestatic

Definition at line 138 of file qqmltypeloader_p.h.

References engine.

◆ getQmldir()

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

Returns a QQmlQmldirData for url.

The QQmlQmldirData may be cached.

Definition at line 1066 of file qqmltypeloader.cpp.

References QHash< Key, T >::insert(), QUrl::isRelative(), QDir::isRelativePath(), load(), Q_ASSERT, url, QQmlFile::urlToLocalFileOrQrc(), and QHash< Key, T >::value().

Referenced by QQmlApplicationEnginePrivate::startLoad().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getScript()

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

Return a QQmlScriptBlob for url.

The QQmlScriptData may be cached.

Definition at line 1032 of file qqmltypeloader.cpp.

References error, QQmlMetaType::findCachedCompilationUnit(), QHash< Key, T >::insert(), QDir::isRelativePath(), load(), loadWithCachedUnit(), QQmlMetaType::NoError, normalize(), Q_ASSERT, QQmlMetaType::RejectAll, url, QQmlFile::urlToLocalFileOrQrc(), and QHash< Key, T >::value().

+ Here is the call graph for this function:

◆ getType() [1/2]

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.

Definition at line 999 of file qqmltypeloader.cpp.

References loadWithStaticData(), and url.

+ Here is the call graph for this function:

◆ getType() [2/2]

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

Returns a QQmlTypeData for the specified url.

The QQmlTypeData may be cached.

Definition at line 945 of file qqmltypeloader.cpp.

References QQmlTypeLoader::Blob::aotCacheMode(), error, QQmlMetaType::findCachedCompilationUnit(), QHash< Key, T >::insert(), QQmlDataBlob::isCompleteOrError(), QDir::isRelativePath(), QQmlFile::isSynchronous(), QQmlThread::isThisThread(), load(), loadWithCachedUnit(), QQmlMetaType::NoError, normalize(), PreferSynchronous, Q_ASSERT, QQmlMetaType::RejectAll, QQmlTypeLoader::Blob::setCachedUnitStatus(), QHash< Key, T >::size(), Synchronous, trimCache(), url, QQmlDataBlob::url(), QQmlFile::urlToLocalFileOrQrc(), QHash< Key, T >::value(), and QQmlThread::waitForNextMessage().

Referenced by QQmlPropertyCacheCreator< ObjectContainer >::createMetaObject().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ importDatabase()

QQmlImportDatabase * QQmlTypeLoader::importDatabase ( ) const

Definition at line 929 of file qqmltypeloader.cpp.

References engine(), and QQmlEnginePrivate::get().

Referenced by QQmlImports::addFileImport().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initializeEngine() [1/2]

void QQmlTypeLoader::initializeEngine ( QQmlEngineExtensionInterface * iface,
const char * uri )

Definition at line 373 of file qqmltypeloader.cpp.

References doInitializeEngine(), and engine().

+ Here is the call graph for this function:

◆ initializeEngine() [2/2]

void QQmlTypeLoader::initializeEngine ( QQmlExtensionInterface * iface,
const char * uri )

Definition at line 378 of file qqmltypeloader.cpp.

References doInitializeEngine(), and engine().

+ Here is the call graph for this function:

◆ injectedScript()

QQmlRefPointer< QQmlScriptBlob > QQmlTypeLoader::injectedScript ( const QUrl & relativeUrl)

Definition at line 1020 of file qqmltypeloader.cpp.

References QHash< Key, T >::constEnd(), QHash< Key, T >::constFind(), and it.

+ Here is the call graph for this function:

◆ injectScript()

void QQmlTypeLoader::injectScript ( const QUrl & relativeUrl,
const QV4::Value & value )

Definition at line 1009 of file qqmltypeloader.cpp.

References QQmlDataBlob::Complete, and QHash< Key, T >::insert().

+ Here is the call graph for this function:

◆ invalidate()

void QQmlTypeLoader::invalidate ( )

Definition at line 82 of file qqmltypeloader.cpp.

Referenced by ~QQmlTypeLoader().

+ Here is the caller graph for this function:

◆ isScriptLoaded()

bool QQmlTypeLoader::isScriptLoaded ( const QUrl & url) const

Definition at line 1415 of file qqmltypeloader.cpp.

References QHash< Key, T >::contains(), and url.

+ Here is the call graph for this function:

◆ isTypeLoaded()

bool QQmlTypeLoader::isTypeLoaded ( const QUrl & url) const

Definition at line 1409 of file qqmltypeloader.cpp.

References QHash< Key, T >::contains(), and url.

+ Here is the call graph for this function:

◆ load()

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

Load the provided blob from the network or filesystem.

The loader must be locked.

Definition at line 196 of file qqmltypeloader.cpp.

References PlainLoader.

Referenced by getQmldir(), getScript(), and getType().

+ Here is the caller graph for this function:

◆ loadWithCachedUnit()

void QQmlTypeLoader::loadWithCachedUnit ( QQmlDataBlob * blob,
const QQmlPrivate::CachedQmlUnit * unit,
Mode mode = PreferSynchronous )

Definition at line 211 of file qqmltypeloader.cpp.

References CachedLoader.

Referenced by getScript(), and getType().

+ Here is the caller graph for this function:

◆ loadWithStaticData()

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.

Definition at line 206 of file qqmltypeloader.cpp.

References StaticLoader.

Referenced by getType().

+ Here is the caller graph for this function:

◆ lock()

void QQmlTypeLoader::lock ( )
inline

Definition at line 171 of file qqmltypeloader_p.h.

◆ normalize()

QUrl QQmlTypeLoader::normalize ( const QUrl & unNormalizedUrl)
static

Definition at line 934 of file qqmltypeloader.cpp.

Referenced by createQQmlType(), QQmlMetaType::findCompositeType(), getScript(), getType(), QV4::ExecutionEngine::loadModule(), QV4::ExecutionEngine::moduleForUrl(), QQmlMetaType::obtainCompilationUnit(), QQmlMetaType::qmlType(), QQmlMetaType::registerCompositeType(), singletonInstanceInfo(), and QQmlMetaType::typeForUrl().

+ Here is the caller graph for this function:

◆ profiler()

quintptr QQmlTypeLoader::profiler ( ) const
inline

Definition at line 184 of file qqmltypeloader_p.h.

◆ qmldirContent()

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.

Definition at line 1258 of file qqmltypeloader.cpp.

References CASE_MISMATCH_ERROR, ERROR, file, QString::fromUtf8(), QStringHash< T >::insert(), QString::isEmpty(), NOT_READABLE_ERROR, QFile::open(), QQml_isFileCaseCorrect(), QIODevice::readAll(), QIODeviceBase::ReadOnly, QUrl::scheme(), QString::size(), url, QQmlFile::urlToLocalFileOrQrc(), and QStringHash< T >::value().

+ Here is the call graph for this function:

◆ setProfiler()

void QQmlTypeLoader::setProfiler ( quintptr )
inline

Definition at line 185 of file qqmltypeloader_p.h.

Referenced by QQmlProfilerAdapter::QQmlProfilerAdapter().

+ Here is the caller graph for this function:

◆ setQmldirContent()

void QQmlTypeLoader::setQmldirContent ( const QString & filePath,
const QString & content )

Definition at line 1310 of file qqmltypeloader.cpp.

References QQmlTypeLoaderQmldirContent::hasContent(), QStringHash< T >::insert(), url, and QStringHash< T >::value().

+ Here is the call graph for this function:

◆ trimCache()

void QQmlTypeLoader::trimCache ( )

Definition at line 1363 of file qqmltypeloader.cpp.

References QHash< Key, T >::begin(), QQmlRefCount::count(), QQmlMetaType::countInternalCompositeTypeSelfReferences(), QHash< Key, T >::end(), QHash< Key, T >::erase(), QQmlMetaType::freeUnusedTypesAndCaches(), QQmlDataBlob::isComplete(), QQmlDataBlob::isError(), iter, Q_ASSERT, and QQmlMetaType::unregisterInternalCompositeType().

Referenced by getType().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unlock()

void QQmlTypeLoader::unlock ( )
inline

Definition at line 172 of file qqmltypeloader_p.h.

Friends And Related Symbol Documentation

◆ CachedLoader

friend struct CachedLoader
friend

Definition at line 246 of file qqmltypeloader_p.h.

Referenced by loadWithCachedUnit().

◆ PlainLoader

friend struct PlainLoader
friend

Definition at line 245 of file qqmltypeloader_p.h.

Referenced by load().

◆ QQmlDataBlob

friend class QQmlDataBlob
friend

Definition at line 193 of file qqmltypeloader_p.h.

◆ QQmlTypeLoaderThread

friend class QQmlTypeLoaderThread
friend

Definition at line 194 of file qqmltypeloader_p.h.

◆ StaticLoader

friend struct StaticLoader
friend

Definition at line 247 of file qqmltypeloader_p.h.

Referenced by loadWithStaticData().


The documentation for this class was generated from the following files: