Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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 = QQmlTypeLoaderThreadData::ChecksumCache

Public Member Functions

 QQmlTypeLoader (QV4::ExecutionEngine *engine)
 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.
template<typename TypeReference>
QByteArray hashDependencies (QV4::CompiledData::ResolvedTypeReferenceMap *resolvedTypeCache, const QList< TypeReference > &compositeSingletons)
QQmlRefPointer< QQmlTypeDatagetType (const QUrl &unNormalizedUrl, Mode mode=PreferSynchronous)
 Returns a QQmlTypeData for the specified url.
QQmlRefPointer< QQmlTypeDatagetType (const QByteArray &data, const QUrl &url, Mode mode=PreferSynchronous)
 Returns a QQmlTypeData for the given data with the provided base url.
QQmlRefPointer< QQmlScriptBlobgetScript (const QUrl &unNormalizedUrl, Mode mode=PreferSynchronous)
QQmlRefPointer< QV4::CompiledData::CompilationUnitinjectModule (const QUrl &relativeUrl, const QV4::CompiledData::Unit *unit)
QQmlRefPointer< QQmlScriptBlobgetScript (const QUrl &unNormalizedUrl, const QUrl &relativeUrl)
 Return a QQmlScriptBlob for unNormalizedUrl or relativeUrl.
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 &filePath)
bool fileExists (const QString &dirPath, 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 loadWithStaticData (const QQmlDataBlob::Ptr &blob, const QByteArray &data, Mode mode=PreferSynchronous)
 Load the provided blob with data.
void drop (const QQmlDataBlob::Ptr &blob)
void initializeEngine (QQmlEngineExtensionInterface *, const char *)
void initializeEngine (QQmlExtensionInterface *, const char *)
void invalidate ()
void addUrlInterceptor (QQmlAbstractUrlInterceptor *urlInterceptor)
void removeUrlInterceptor (QQmlAbstractUrlInterceptor *urlInterceptor)
QList< QQmlAbstractUrlInterceptor * > urlInterceptors () const
QUrl interceptUrl (const QUrl &url, QQmlAbstractUrlInterceptor::DataType type) const
bool hasUrlInterceptors () const
quintptr profiler () const
void setProfiler (quintptr)
QStringList importPathList () const
void setImportPathList (const QStringList &paths)
void addImportPath (const QString &dir)
QStringList pluginPathList () const
void setPluginPathList (const QStringList &paths)
void addPluginPath (const QString &path)
void setPluginInitialized (const QString &plugin)
bool isPluginInitialized (const QString &plugin) const
void setModulePluginProcessingDone (const QString &module)
bool isModulePluginProcessingDone (const QString &module)
bool writeCacheFile ()
bool readCacheFile ()
bool isDebugging ()

Static Public Member Functions

template<typename Engine, typename EnginePrivate = QQmlEnginePrivate, typename = std::enable_if_t<std::is_base_of_v<QJSEngine, Engine>>>
static QQmlTypeLoaderget (Engine *engine)
template<typename Engine, typename = std::enable_if_t<std::is_base_of_v<QJSEnginePrivate, Engine>>>
static QQmlTypeLoaderget (Engine *engine)
static void sanitizeUNCPath (QString *path)

Friends

struct PlainLoader
struct CachedLoader
struct StaticLoader
class QQmlDataBlob
class QQmlTypeLoaderThread

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 43 of file qqmltypeloader_p.h.

Member Typedef Documentation

◆ ChecksumCache

Member Enumeration Documentation

◆ Mode

Enumerator
PreferSynchronous 
Asynchronous 
Synchronous 

Definition at line 48 of file qqmltypeloader_p.h.

Constructor & Destructor Documentation

◆ QQmlTypeLoader()

QQmlTypeLoader::QQmlTypeLoader ( QV4::ExecutionEngine * engine)

Constructs a new type loader that uses the given engine.

Definition at line 1217 of file qqmltypeloader.cpp.

◆ ~QQmlTypeLoader()

QQmlTypeLoader::~QQmlTypeLoader ( )

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

Definition at line 1296 of file qqmltypeloader.cpp.

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 1506 of file qqmltypeloader.cpp.

◆ addImportPath()

void QQmlTypeLoader::addImportPath ( const QString & path)

Definition at line 535 of file qqmltypeloader.cpp.

◆ addPluginPath()

void QQmlTypeLoader::addPluginPath ( const QString & path)

Definition at line 600 of file qqmltypeloader.cpp.

◆ addUrlInterceptor()

void QQmlTypeLoader::addUrlInterceptor ( QQmlAbstractUrlInterceptor * urlInterceptor)

Definition at line 93 of file qqmltypeloader.cpp.

◆ clearCache()

void QQmlTypeLoader::clearCache ( )

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

Definition at line 1809 of file qqmltypeloader.cpp.

Referenced by QQmlPreviewServiceImpl::messageReceived().

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 1679 of file qqmltypeloader.cpp.

◆ drop()

void QQmlTypeLoader::drop ( const QQmlDataBlob::Ptr & blob)

Definition at line 270 of file qqmltypeloader.cpp.

◆ fileExists() [1/2]

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

Definition at line 1578 of file qqmltypeloader.cpp.

◆ fileExists() [2/2]

bool QQmlTypeLoader::fileExists ( const QString & filePath)
inline

Definition at line 197 of file qqmltypeloader_p.h.

◆ get() [1/2]

template<typename Engine, typename EnginePrivate = QQmlEnginePrivate, typename = std::enable_if_t<std::is_base_of_v<QJSEngine, Engine>>>
QQmlTypeLoader * QQmlTypeLoader::get ( Engine * engine)
inlinestatic

Definition at line 139 of file qqmltypeloader_p.h.

◆ get() [2/2]

template<typename Engine, typename = std::enable_if_t<std::is_base_of_v<QJSEnginePrivate, Engine>>>
QQmlTypeLoader * QQmlTypeLoader::get ( Engine * engine)
inlinestatic

Definition at line 147 of file qqmltypeloader_p.h.

◆ getQmldir()

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

Returns a QQmlQmldirData for url.

The QQmlQmldirData may be cached.

Definition at line 1474 of file qqmltypeloader.cpp.

◆ getScript() [1/2]

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

Return a QQmlScriptBlob for unNormalizedUrl or relativeUrl.

This assumes PreferSynchronous, and therefore the result may not be ready yet.

Definition at line 1437 of file qqmltypeloader.cpp.

◆ getScript() [2/2]

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

Definition at line 1388 of file qqmltypeloader.cpp.

◆ 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 1373 of file qqmltypeloader.cpp.

◆ 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 1339 of file qqmltypeloader.cpp.

◆ hashDependencies()

template<typename TypeReference>
QByteArray QQmlTypeLoader::hashDependencies ( QV4::CompiledData::ResolvedTypeReferenceMap * resolvedTypeCache,
const QList< TypeReference > & compositeSingletons )
inline

Definition at line 167 of file qqmltypeloader_p.h.

◆ hasUrlInterceptors()

bool QQmlTypeLoader::hasUrlInterceptors ( ) const

Definition at line 132 of file qqmltypeloader.cpp.

◆ importPathList()

QStringList QQmlTypeLoader::importPathList ( ) const
inline

Definition at line 245 of file qqmltypeloader_p.h.

◆ initializeEngine() [1/2]

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

Definition at line 423 of file qqmltypeloader.cpp.

◆ initializeEngine() [2/2]

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

Definition at line 429 of file qqmltypeloader.cpp.

◆ injectModule()

QQmlRefPointer< QV4::CompiledData::CompilationUnit > QQmlTypeLoader::injectModule ( const QUrl & relativeUrl,
const QV4::CompiledData::Unit * unit )

Definition at line 1414 of file qqmltypeloader.cpp.

◆ interceptUrl()

QUrl QQmlTypeLoader::interceptUrl ( const QUrl & url,
QQmlAbstractUrlInterceptor::DataType type ) const

Definition at line 124 of file qqmltypeloader.cpp.

◆ invalidate()

void QQmlTypeLoader::invalidate ( )

Definition at line 78 of file qqmltypeloader.cpp.

◆ isDebugging()

bool QQmlTypeLoader::isDebugging ( )

Definition at line 1156 of file qqmltypeloader.cpp.

◆ isModulePluginProcessingDone()

bool QQmlTypeLoader::isModulePluginProcessingDone ( const QString & module)
inline

Definition at line 277 of file qqmltypeloader_p.h.

◆ isPluginInitialized()

bool QQmlTypeLoader::isPluginInitialized ( const QString & plugin) const
inline

Definition at line 266 of file qqmltypeloader_p.h.

◆ isScriptLoaded()

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

Definition at line 1913 of file qqmltypeloader.cpp.

◆ isTypeLoaded()

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

Definition at line 1907 of file qqmltypeloader.cpp.

◆ loadWithStaticData()

void QQmlTypeLoader::loadWithStaticData ( const QQmlDataBlob::Ptr & 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 256 of file qqmltypeloader.cpp.

◆ pluginPathList()

QStringList QQmlTypeLoader::pluginPathList ( ) const
inline

Definition at line 253 of file qqmltypeloader_p.h.

◆ profiler()

quintptr QQmlTypeLoader::profiler ( ) const
inline

Definition at line 234 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 1723 of file qqmltypeloader.cpp.

◆ readCacheFile()

bool QQmlTypeLoader::readCacheFile ( )

Definition at line 1161 of file qqmltypeloader.cpp.

◆ removeUrlInterceptor()

void QQmlTypeLoader::removeUrlInterceptor ( QQmlAbstractUrlInterceptor * urlInterceptor)

Definition at line 100 of file qqmltypeloader.cpp.

◆ sanitizeUNCPath()

void QQmlTypeLoader::sanitizeUNCPath ( QString * path)
inlinestatic

Definition at line 152 of file qqmltypeloader_p.h.

◆ setImportPathList()

void QQmlTypeLoader::setImportPathList ( const QStringList & paths)

Definition at line 573 of file qqmltypeloader.cpp.

◆ setModulePluginProcessingDone()

void QQmlTypeLoader::setModulePluginProcessingDone ( const QString & module)
inline

Definition at line 272 of file qqmltypeloader_p.h.

◆ setPluginInitialized()

void QQmlTypeLoader::setPluginInitialized ( const QString & plugin)
inline

Definition at line 261 of file qqmltypeloader_p.h.

◆ setPluginPathList()

void QQmlTypeLoader::setPluginPathList ( const QStringList & paths)

Definition at line 590 of file qqmltypeloader.cpp.

◆ setProfiler()

void QQmlTypeLoader::setProfiler ( quintptr )
inline

Definition at line 235 of file qqmltypeloader_p.h.

◆ setQmldirContent()

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

Definition at line 1778 of file qqmltypeloader.cpp.

◆ trimCache()

void QQmlTypeLoader::trimCache ( )

Definition at line 1835 of file qqmltypeloader.cpp.

◆ urlInterceptors()

QList< QQmlAbstractUrlInterceptor * > QQmlTypeLoader::urlInterceptors ( ) const

Definition at line 107 of file qqmltypeloader.cpp.

◆ writeCacheFile()

bool QQmlTypeLoader::writeCacheFile ( )

Definition at line 1166 of file qqmltypeloader.cpp.

◆ CachedLoader

friend struct CachedLoader
friend

Definition at line 295 of file qqmltypeloader_p.h.

◆ PlainLoader

friend struct PlainLoader
friend

Definition at line 294 of file qqmltypeloader_p.h.

◆ QQmlDataBlob

friend class QQmlDataBlob
friend

Definition at line 298 of file qqmltypeloader_p.h.

◆ QQmlTypeLoaderThread

friend class QQmlTypeLoaderThread
friend

Definition at line 299 of file qqmltypeloader_p.h.

◆ StaticLoader

friend struct StaticLoader
friend

Definition at line 296 of file qqmltypeloader_p.h.


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