Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
QQmlFile Class Reference

The QQmlFile class gives access to local and remote files. More...

#include <qqmlfile.h>

+ Collaboration diagram for QQmlFile:

Public Types

enum  Status { Null , Ready , Error , Loading }
 

Public Member Functions

 QQmlFile ()
 
 QQmlFile (QQmlEngine *, const QUrl &)
 
 QQmlFile (QQmlEngine *, const QString &)
 
 ~QQmlFile ()
 
bool isNull () const
 
bool isReady () const
 
bool isError () const
 
bool isLoading () const
 
QUrl url () const
 
Status status () const
 
QString error () const
 
qint64 size () const
 
const char * data () const
 
QByteArray dataByteArray () const
 
void load (QQmlEngine *, const QUrl &)
 
void load (QQmlEngine *, const QString &)
 
void clear ()
 
void clear (QObject *)
 

Static Public Member Functions

static bool isSynchronous (const QString &url)
 Returns true if QQmlFile will open url synchronously.
 
static bool isSynchronous (const QUrl &url)
 Returns true if QQmlFile will open url synchronously.
 
static bool isLocalFile (const QString &url)
 Returns true if url is a local file that can be opened with QFile.
 
static bool isLocalFile (const QUrl &url)
 Returns true if url is a local file that can be opened with QFile.
 
static QString urlToLocalFileOrQrc (const QString &)
 If url is a local file returns a path suitable for passing to QFile.
 
static QString urlToLocalFileOrQrc (const QUrl &)
 If url is a local file returns a path suitable for passing to QFile.
 

Detailed Description

The QQmlFile class gives access to local and remote files.

Supports file:// and qrc:/ uris and whatever QNetworkAccessManager supports.

Definition at line 17 of file qqmlfile.h.

Member Enumeration Documentation

◆ Status

Enumerator
Null 
Ready 
Error 
Loading 

Definition at line 25 of file qqmlfile.h.

Constructor & Destructor Documentation

◆ QQmlFile() [1/3]

QQmlFile::QQmlFile ( )

Definition at line 162 of file qqmlfile.cpp.

◆ QQmlFile() [2/3]

QQmlFile::QQmlFile ( QQmlEngine e,
const QUrl url 
)

Definition at line 167 of file qqmlfile.cpp.

References e, load(), and url().

+ Here is the call graph for this function:

◆ QQmlFile() [3/3]

QQmlFile::QQmlFile ( QQmlEngine e,
const QString url 
)

Definition at line 173 of file qqmlfile.cpp.

◆ ~QQmlFile()

QQmlFile::~QQmlFile ( )

Definition at line 178 of file qqmlfile.cpp.

Member Function Documentation

◆ clear() [1/2]

void QQmlFile::clear ( )

Definition at line 322 of file qqmlfile.cpp.

References QQmlFilePrivate::data, QQmlFilePrivate::error, QQmlFilePrivate::None, QQmlFilePrivate::url, and QQmlFilePrivate::urlString.

Referenced by clear(), load(), and load().

+ Here is the caller graph for this function:

◆ clear() [2/2]

void QQmlFile::clear ( QObject )

Definition at line 330 of file qqmlfile.cpp.

References clear().

+ Here is the call graph for this function:

◆ data()

const char * QQmlFile::data ( ) const

Definition at line 248 of file qqmlfile.cpp.

References QByteArray::constData(), and QQmlFilePrivate::data.

+ Here is the call graph for this function:

◆ dataByteArray()

QByteArray QQmlFile::dataByteArray ( ) const

Definition at line 253 of file qqmlfile.cpp.

References QQmlFilePrivate::data.

◆ error()

QString QQmlFile::error ( ) const

◆ isError()

bool QQmlFile::isError ( ) const

Definition at line 197 of file qqmlfile.cpp.

References Error, and status().

+ Here is the call graph for this function:

◆ isLoading()

bool QQmlFile::isLoading ( ) const

Definition at line 202 of file qqmlfile.cpp.

References Loading, and status().

+ Here is the call graph for this function:

◆ isLocalFile() [1/2]

bool QQmlFile::isLocalFile ( const QString url)
static

Returns true if url is a local file that can be opened with QFile.

Local file urls have either a qrc: or file: scheme.

Note
On Android, urls with assets: or content: scheme are also considered local files.

Definition at line 549 of file qqmlfile.cpp.

References authorityOffset(), Qt::CaseInsensitive, file_string, hasScheme(), qrc_string, and url().

Referenced by QQmlImports::addFileImport(), QQmlImportDatabase::importPathList(), load(), load(), QV4::ExecutableCompilationUnit::loadFromDisk(), QQmlImportDatabase::locateLocalQmldir(), QQuickStyleSpec::path(), QQmlXmlListModel::reload(), and QV4::ExecutableCompilationUnit::saveToDisk().

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

◆ isLocalFile() [2/2]

bool QQmlFile::isLocalFile ( const QUrl url)
static

Returns true if url is a local file that can be opened with QFile.

Local file urls have either a qrc:/ or file:// scheme.

Note
On Android, urls with assets:/ scheme are also considered local files.

Definition at line 469 of file qqmlfile.cpp.

References QUrl::authority(), Qt::CaseInsensitive, file_string, QString::isEmpty(), QString::length(), qrc_string, QUrl::scheme(), QString::size(), QString::startsWith(), and url().

+ Here is the call graph for this function:

◆ isNull()

bool QQmlFile::isNull ( ) const

Definition at line 187 of file qqmlfile.cpp.

References Null, and status().

+ Here is the call graph for this function:

◆ isReady()

bool QQmlFile::isReady ( ) const

Definition at line 192 of file qqmlfile.cpp.

References Ready, and status().

+ Here is the call graph for this function:

◆ isSynchronous() [1/2]

bool QQmlFile::isSynchronous ( const QString url)
static

Returns true if QQmlFile will open url synchronously.

Synchronous urls have a qrc:/ or file:// scheme.

Note
On Android, urls with assets:/ scheme are also considered synchronous.

Definition at line 415 of file qqmlfile.cpp.

References Qt::CaseInsensitive, file_string, qrc_string, and url().

Referenced by QQmlTypeLoader::getType().

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

◆ isSynchronous() [2/2]

bool QQmlFile::isSynchronous ( const QUrl url)
static

Returns true if QQmlFile will open url synchronously.

Synchronous urls have a qrc:/ or file:// scheme.

Note
On Android, urls with assets:/ scheme are also considered synchronous.

Definition at line 388 of file qqmlfile.cpp.

References Qt::CaseInsensitive, QString::compare(), file_string, QString::length(), qrc_string, QUrl::scheme(), QString::size(), and url().

+ Here is the call graph for this function:

◆ load() [1/2]

void QQmlFile::load ( QQmlEngine engine,
const QString url 
)

Definition at line 288 of file qqmlfile.cpp.

References QQmlFilePrivate::CaseMismatch, clear(), QQmlFilePrivate::data, engine, QQmlFilePrivate::error, file, isLocalFile(), QQmlFilePrivate::NotFound, QFile::open(), Q_ASSERT, QQml_isFileCaseCorrect(), QIODevice::readAll(), QIODeviceBase::ReadOnly, QQmlFilePrivate::url, url(), QQmlFilePrivate::urlString, and urlToLocalFileOrQrc().

+ Here is the call graph for this function:

◆ load() [2/2]

void QQmlFile::load ( QQmlEngine engine,
const QUrl url 
)

Definition at line 258 of file qqmlfile.cpp.

References QQmlFilePrivate::CaseMismatch, clear(), QQmlFilePrivate::data, engine, QQmlFilePrivate::error, file, isLocalFile(), QQmlFilePrivate::NotFound, QFile::open(), Q_ASSERT, QQml_isFileCaseCorrect(), QIODevice::readAll(), QIODeviceBase::ReadOnly, QQmlFilePrivate::url, url(), and urlToLocalFileOrQrc().

Referenced by QQmlFile().

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

◆ size()

qint64 QQmlFile::size ( ) const

Definition at line 243 of file qqmlfile.cpp.

References QQmlFilePrivate::data, and QByteArray::size().

+ Here is the call graph for this function:

◆ status()

QQmlFile::Status QQmlFile::status ( ) const

Definition at line 216 of file qqmlfile.cpp.

References QQmlFilePrivate::error, Error, QUrl::isEmpty(), QString::isEmpty(), Loading, QQmlFilePrivate::None, Null, Ready, QQmlFilePrivate::url, and QQmlFilePrivate::urlString.

Referenced by isError(), isLoading(), isNull(), and isReady().

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

◆ url()

QUrl QQmlFile::url ( ) const

Definition at line 207 of file qqmlfile.cpp.

References QString::isEmpty(), QQmlFilePrivate::url, and QQmlFilePrivate::urlString.

Referenced by QQmlFile(), isLocalFile(), isLocalFile(), isSynchronous(), isSynchronous(), load(), load(), urlToLocalFileOrQrc(), and urlToLocalFileOrQrc().

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

◆ urlToLocalFileOrQrc() [1/2]

QString QQmlFile::urlToLocalFileOrQrc ( const QString url)
static

If url is a local file returns a path suitable for passing to QFile.

Otherwise returns an empty string.

Definition at line 643 of file qqmlfile.cpp.

References Qt::CaseInsensitive, hasScheme(), isDoubleSlashed(), Q_ASSERT, QStringLiteral, toLocalFile(), and url().

Referenced by QQmlTypeLoader::absoluteFilePath(), QQmlImports::addFileImport(), QQmlImportDatabase::addImportPath(), QQuickFileDialogDelegatePrivate::chooseFile(), QQuickPdfDocument::classBegin(), QV4::ExecutionEngine::compileModule(), QQuickFolderListModel::componentComplete(), createPixmapDataSync(), QQuickFolderBreadcrumbBarPrivate::crumbPathsForFolder(), QQmlTypeLoader::fileExists(), QQuickControlsTestUtils::forEachControl(), QQuick3DPhysicsHeightFieldManager::getHeightField(), QQuick3DPhysicsMeshManager::getMesh(), QQmlTypeLoader::getQmldir(), QQmlTypeLoader::getScript(), QQmlTypeLoader::getType(), QQuickFolderBreadcrumbBarPrivate::goUp(), QQmlImports::isLocal(), QQmlImports::isLocal(), QQuickAnimatedImage::load(), QQuickBorderImage::load(), load(), load(), QV4::ExecutableCompilationUnit::loadFromDisk(), QV4::ExecutableCompilationUnit::localCacheFilePath(), QQmlImportDatabase::locateLocalQmldir(), QV4Include::method_include(), QQuickFileDialog::onShow(), QQuickFolderDialog::onShow(), QQmlError::operator<<(), QQuickStyleSpec::path(), QSGRhiGuiThreadShaderEffectManager::prepareShaderCode(), QQmlTypeLoader::qmldirContent(), QWavefrontMesh::readData(), QQmlXmlListModel::reload(), QQuickImageBase::resolve2xLocalFile(), resolveImagePath(), QQuickFolderListModelPrivate::resolvePath(), QSSGShaderUtils::resolveShader(), QQmlImportInstance::resolveType(), QQuickFileDialogImpl::setCurrentFolder(), QQuickFolderDialogImpl::setCurrentFolder(), QQuickFontLoader::setSource(), QQuickPdfDocument::setSource(), QQuickImageSelector::setUrl(), QQmlApplicationEnginePrivate::startLoad(), QQuickFolderBreadcrumbBarPrivate::toggleTextFieldVisibility(), QQuick3DModel::translateMeshSource(), QQuickFileDialogImplPrivate::updateSelectedFile(), QQuickFolderDialogImplPrivate::updateSelectedFolder(), QQuick3DModel::updateSpatialNode(), TestHTTPServer::wait(), and QQmlPreviewFileLoader::whitelist().

+ Here is the call graph for this function:

◆ urlToLocalFileOrQrc() [2/2]

QString QQmlFile::urlToLocalFileOrQrc ( const QUrl url)
static

If url is a local file returns a path suitable for passing to QFile.

Otherwise returns an empty string.

Definition at line 591 of file qqmlfile.cpp.

References QUrl::authority(), Qt::CaseInsensitive, QString::compare(), QString::isEmpty(), QUrl::path(), QUrl::scheme(), QUrl::toLocalFile(), QUrl::toString(), and url().

+ Here is the call graph for this function:

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