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
QQmlAbstractUrlInterceptor Class Referenceabstract

\inmodule QtQml More...

#include <qqmlabstracturlinterceptor.h>

+ Inheritance diagram for QQmlAbstractUrlInterceptor:
+ Collaboration diagram for QQmlAbstractUrlInterceptor:

Public Types

enum  DataType { QmlFile = 0 , JavaScriptFile = 1 , QmldirFile = 2 , UrlString = 0x1000 }
 Specifies where URL interception is taking place. More...
 

Public Member Functions

 QQmlAbstractUrlInterceptor ()=default
 Constructor for QQmlAbstractUrlInterceptor.
 
virtual ~QQmlAbstractUrlInterceptor ()=default
 Destructor for QQmlAbstractUrlInterceptor.
 
virtual QUrl intercept (const QUrl &path, DataType type)=0
 A pure virtual function where you can intercept the url.
 

Detailed Description

\inmodule QtQml

allows you to control QML file loading.

QQmlAbstractUrlInterceptor is an interface which can be used to alter URLs before they are used by the QML engine. This is primarily useful for altering file urls into other file urls, such as selecting different graphical assets for the current platform.

Relative URLs are intercepted after being resolved against the file path of the current QML context. URL interception also occurs after setting the base path for a loaded QML file. This means that the content loaded for that QML file uses the intercepted URL, but inside the file the pre-intercepted URL is used for resolving relative paths. This allows for interception of .qml file loading without needing all paths (or local types) inside intercepted content to insert a different relative path.

Compared to setNetworkAccessManagerFactory, QQmlAbstractUrlInterceptor affects all URLs and paths, including local files and embedded resource files. QQmlAbstractUrlInterceptor is synchronous, and for asynchronous files must return a url with an asynchronous scheme (such as http or a custom scheme handled by your own custom QNetworkAccessManager). You can use a QQmlAbstractUrlInterceptor to change file URLs into networked URLs which are handled by your own custom QNetworkAccessManager.

To implement support for a custom networked scheme, see setNetworkAccessManagerFactory.

Definition at line 13 of file qqmlabstracturlinterceptor.h.

Member Enumeration Documentation

◆ DataType

Specifies where URL interception is taking place.

Because QML loads qmldir files for locating types, there are two URLs involved in loading a QML type. The URL of the (possibly implicit) qmldir used for locating the type and the URL of the file which defines the type. Intercepting both leads to either complex URL replacement or double URL replacements for the same file.

\value QmldirFile The URL being intercepted is for a Qmldir file. Intercepting this, but not the QmlFile, allows for swapping out entire sub trees. \value JavaScriptFile The URL being intercepted is an import for a Javascript file. \value QmlFile The URL being intercepted is for a Qml file. Intercepting this, but not the Qmldir file, leaves the base dir of a QML file untouched and acts like replacing the file with another file. \value UrlString The URL being intercepted is a url property in a QML file, and not being used to load a file through the engine.

Enumerator
QmlFile 
JavaScriptFile 
QmldirFile 
UrlString 

Definition at line 16 of file qqmlabstracturlinterceptor.h.

Constructor & Destructor Documentation

◆ QQmlAbstractUrlInterceptor()

QQmlAbstractUrlInterceptor::QQmlAbstractUrlInterceptor ( )
default

Constructor for QQmlAbstractUrlInterceptor.

◆ ~QQmlAbstractUrlInterceptor()

QQmlAbstractUrlInterceptor::~QQmlAbstractUrlInterceptor ( )
virtualdefault

Destructor for QQmlAbstractUrlInterceptor.

Member Function Documentation

◆ intercept()

QUrl QQmlAbstractUrlInterceptor::intercept ( const QUrl & url,
DataType type )
pure virtual

A pure virtual function where you can intercept the url.

The returned value is taken as the new value for the url. The type of url being intercepted is given by the type variable.

Your implementation of this function must be thread-safe, as it can be called from multiple threads at the same time.

Implemented in QQmlFileSelectorInterceptor.


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