![]() |
Qt 6.x
The Qt SDK
|
The QQmlEngine class provides an environment for instantiating QML components. More...
#include <qqmlengine.h>
Public Slots | |
void | retranslate () |
Refreshes all binding expressions that use strings marked for translation. | |
![]() | |
void | deleteLater () |
\threadsafe | |
Signals | |
void | offlineStoragePathChanged () |
This signal is emitted when \l offlineStoragePath changes. | |
void | quit () |
This signal is emitted when the QML loaded by the engine would like to quit. | |
void | exit (int retCode) |
This signal is emitted when the QML loaded by the engine would like to exit from the event loop with the specified return code retCode. | |
void | warnings (const QList< QQmlError > &warnings) |
This signal is emitted when warnings messages are generated by QML. | |
![]() | |
void | uiLanguageChanged () |
![]() | |
void | destroyed (QObject *=nullptr) |
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked. | |
void | objectNameChanged (const QString &objectName, QPrivateSignal) |
This signal is emitted after the object's name has been changed. | |
Public Member Functions | |
QQmlEngine (QObject *p=nullptr) | |
Create a new QQmlEngine with the given parent. | |
~QQmlEngine () override | |
Destroys the QQmlEngine. | |
QQmlContext * | rootContext () const |
Returns the engine's root context. | |
void | clearComponentCache () |
Clears the engine's internal component cache. | |
void | trimComponentCache () |
Trims the engine's internal component cache. | |
void | clearSingletons () |
Clears all singletons the engine owns. | |
QStringList | importPathList () const |
Returns the list of directories where the engine searches for installed modules in a URL-based directory structure. | |
void | setImportPathList (const QStringList &paths) |
Sets paths as the list of directories where the engine searches for installed modules in a URL-based directory structure. | |
void | addImportPath (const QString &dir) |
Adds path as a directory where the engine searches for installed modules in a URL-based directory structure. | |
QStringList | pluginPathList () const |
Returns the list of directories where the engine searches for native plugins for imported modules (referenced in the qmldir file). | |
void | setPluginPathList (const QStringList &paths) |
Sets the list of directories where the engine searches for native plugins for imported modules (referenced in the qmldir file) to paths. | |
void | addPluginPath (const QString &dir) |
Adds path as a directory where the engine searches for native plugins for imported modules (referenced in the qmldir file). | |
void | addUrlInterceptor (QQmlAbstractUrlInterceptor *urlInterceptor) |
Adds a urlInterceptor to be used when resolving URLs in QML. | |
void | removeUrlInterceptor (QQmlAbstractUrlInterceptor *urlInterceptor) |
Remove a urlInterceptor that was previously added using \l addUrlInterceptor. | |
QList< QQmlAbstractUrlInterceptor * > | urlInterceptors () const |
Returns the list of currently active URL interceptors. | |
QUrl | interceptUrl (const QUrl &url, QQmlAbstractUrlInterceptor::DataType type) const |
Run the current URL interceptors on the given url of the given type and return the result. | |
void | addImageProvider (const QString &id, QQmlImageProviderBase *) |
Sets the provider to use for images requested via the image: url scheme, with host providerId. | |
QQmlImageProviderBase * | imageProvider (const QString &id) const |
Returns the image provider set for providerId if found; otherwise returns \nullptr. | |
void | removeImageProvider (const QString &id) |
Removes the image provider for providerId. | |
void | setIncubationController (QQmlIncubationController *) |
Sets the engine's incubation controller. | |
QQmlIncubationController * | incubationController () const |
Returns the currently set incubation controller, or 0 if no controller has been set. | |
void | setOfflineStoragePath (const QString &dir) |
QString | offlineStoragePath () const |
QString | offlineStorageDatabaseFilePath (const QString &databaseName) const |
Returns the file path where a \l{QtQuick.LocalStorage}{Local Storage} database with the identifier databaseName is (or would be) located. | |
QUrl | baseUrl () const |
Return the base URL for this engine. | |
void | setBaseUrl (const QUrl &) |
Set the base URL for this engine to url. | |
bool | outputWarningsToStandardError () const |
Returns true if warning messages will be output to stderr in addition to being emitted by the warnings() signal, otherwise false. | |
void | setOutputWarningsToStandardError (bool) |
Set whether warning messages will be output to stderr to enabled. | |
void | markCurrentFunctionAsTranslationBinding () |
template<typename T > | |
T | singletonInstance (int qmlTypeId) |
\qmlproperty string Qt::uiLanguage | |
template<typename T > | |
T | singletonInstance (QAnyStringView moduleName, QAnyStringView typeName) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns the instance of a singleton type named typeName from the module specified by uri. | |
void | captureProperty (QObject *object, const QMetaProperty &property) const |
template<> | |
QJSValue | singletonInstance (int qmlTypeId) |
template<> | |
QJSValue | singletonInstance (QAnyStringView uri, QAnyStringView typeName) |
template<> | |
Q_QML_EXPORT QJSValue | singletonInstance (int qmlTypeId) |
template<> | |
Q_QML_EXPORT QJSValue | singletonInstance (QAnyStringView uri, QAnyStringView typeName) |
![]() | |
QJSEngine () | |
Constructs a QJSEngine object. | |
QJSEngine (QObject *parent) | |
Constructs a QJSEngine object with the given parent. | |
~QJSEngine () override | |
Destroys this QJSEngine. | |
QJSValue | globalObject () const |
Returns this engine's Global Object. | |
QJSValue | evaluate (const QString &program, const QString &fileName=QString(), int lineNumber=1, QStringList *exceptionStackTrace=nullptr) |
Evaluates program, using lineNumber as the base line number, and returns the result of the evaluation. | |
QJSValue | importModule (const QString &fileName) |
Imports the module located at fileName and returns a module namespace object that contains all exported variables, constants and functions as properties. | |
bool | registerModule (const QString &moduleName, const QJSValue &value) |
Registers a QJSValue to serve as a module. | |
QJSValue | newObject () |
Creates a JavaScript object of class Object. | |
QJSValue | newSymbol (const QString &name) |
QJSValue | newArray (uint length=0) |
Creates a JavaScript object of class Array with the given length. | |
QJSValue | newQObject (QObject *object) |
Creates a JavaScript object that wraps the given QObject object, using JavaScriptOwnership. | |
QJSValue | newQMetaObject (const QMetaObject *metaObject) |
template<typename T > | |
QJSValue | newQMetaObject () |
QJSValue | newErrorObject (QJSValue::ErrorType errorType, const QString &message=QString()) |
template<typename T > | |
QJSValue | toScriptValue (const T &value) |
Creates a QJSValue with the given value. | |
template<typename T > | |
QJSManagedValue | toManagedValue (const T &value) |
Creates a QJSManagedValue with the given value. | |
template<typename T > | |
QJSPrimitiveValue | toPrimitiveValue (const T &value) |
Creates a QJSPrimitiveValue with the given value. | |
template<typename T > | |
T | fromScriptValue (const QJSValue &value) |
Returns the given value converted to the template type {T}. | |
template<typename T > | |
T | fromManagedValue (const QJSManagedValue &value) |
Returns the given value converted to the template type {T}. | |
template<typename T > | |
T | fromPrimitiveValue (const QJSPrimitiveValue &value) |
Returns the given value converted to the template type {T}. | |
template<typename T > | |
T | fromVariant (const QVariant &value) |
Returns the given value converted to the template type {T}. | |
template<typename From , typename To > | |
To | coerceValue (const From &from) |
Returns the given from converted to the template type {To}. | |
void | collectGarbage () |
Runs the garbage collector. | |
void | installExtensions (Extensions extensions, const QJSValue &object=QJSValue()) |
void | setInterrupted (bool interrupted) |
bool | isInterrupted () const |
QV4::ExecutionEngine * | handle () const |
void | throwError (const QString &message) |
Throws a run-time error (exception) with the given message. | |
void | throwError (QJSValue::ErrorType errorType, const QString &message=QString()) |
void | throwError (const QJSValue &error) |
bool | hasError () const |
Returns true if the last JavaScript execution resulted in an exception or if throwError() was called. | |
QJSValue | catchError () |
If an exception is currently pending, catches it and returns it as a QJSValue. | |
QString | uiLanguage () const |
void | setUiLanguage (const QString &language) |
![]() | |
Q_INVOKABLE | QObject (QObject *parent=nullptr) |
Constructs an object with parent object parent. | |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. | |
virtual bool | event (QEvent *event) |
This virtual function receives events to an object and should return true if the event e was recognized and processed. | |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
Filters events if this object has been installed as an event filter for the watched object. | |
QString | objectName () const |
Q_WEAK_OVERLOAD void | setObjectName (const QString &name) |
Sets the object's name to name. | |
void | setObjectName (QAnyStringView name) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QBindable< QString > | bindableObjectName () |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false . | |
bool | isWindowType () const |
Returns true if the object is a window; otherwise returns false . | |
bool | isQuickItemType () const |
Returns true if the object is a QQuickItem; otherwise returns false . | |
bool | signalsBlocked () const noexcept |
Returns true if signals are blocked; otherwise returns false . | |
bool | blockSignals (bool b) noexcept |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). | |
QThread * | thread () const |
Returns the thread in which the object lives. | |
void | moveToThread (QThread *thread) |
Changes the thread affinity for this object and its children. | |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds. | |
int | startTimer (std::chrono::milliseconds time, Qt::TimerType timerType=Qt::CoarseTimer) |
void | killTimer (int id) |
Kills the timer with timer identifier, id. | |
template<typename T > | |
T | findChild (const QString &aName=QString(), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object. | |
template<typename T > | |
QList< T > | findChildren (const QString &aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. | |
template<typename T > | |
QList< T > | findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const QObjectList & | children () const |
Returns a list of child objects. | |
void | setParent (QObject *parent) |
Makes the object a child of parent. | |
void | installEventFilter (QObject *filterObj) |
Installs an event filter filterObj on this object. | |
void | removeEventFilter (QObject *obj) |
Removes an event filter object obj from this object. | |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const |
bool | disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const |
bool | disconnect (const QObject *receiver, const char *member=nullptr) const |
void | dumpObjectTree () const |
Dumps a tree of children to the debug output. | |
void | dumpObjectInfo () const |
Dumps information about signal connections, etc. | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. | |
bool | setProperty (const char *name, QVariant &&value) |
QVariant | property (const char *name) const |
Returns the value of the object's name property. | |
QList< QByteArray > | dynamicPropertyNames () const |
QBindingStorage * | bindingStorage () |
const QBindingStorage * | bindingStorage () const |
QObject * | parent () const |
Returns a pointer to the parent object. | |
bool | inherits (const char *classname) const |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false . | |
Static Public Member Functions | |
static QQmlContext * | contextForObject (const QObject *) |
Returns the QQmlContext for the object, or nullptr if no context has been set. | |
static void | setContextForObject (QObject *, QQmlContext *) |
Sets the QQmlContext for the object to context. | |
![]() | |
static void | setObjectOwnership (QObject *, ObjectOwnership) |
Sets the ownership of object. | |
static ObjectOwnership | objectOwnership (QObject *) |
Returns the ownership of object. | |
![]() | |
static QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
\threadsafe | |
static QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
\threadsafe | |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static bool | disconnect (const QMetaObject::Connection &) |
Disconnect a connection. | |
template<typename Func1 , typename Func2 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot) |
template<typename Func1 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero) |
Protected Member Functions | |
QQmlEngine (QQmlEnginePrivate &dd, QObject *p) | |
bool | event (QEvent *) override |
\reimp | |
![]() | |
QJSEngine (QJSEnginePrivate &dd, QObject *parent=nullptr) | |
![]() | |
QObject * | sender () const |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr. | |
int | senderSignalIndex () const |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. | |
bool | isSignalConnected (const QMetaMethod &signal) const |
virtual void | timerEvent (QTimerEvent *event) |
This event handler can be reimplemented in a subclass to receive timer events for the object. | |
virtual void | childEvent (QChildEvent *event) |
This event handler can be reimplemented in a subclass to receive child events. | |
virtual void | customEvent (QEvent *event) |
This event handler can be reimplemented in a subclass to receive custom events. | |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
QObject (QObjectPrivate &dd, QObject *parent=nullptr) | |
Properties | |
QString | offlineStoragePath |
the directory for storing offline user data | |
![]() | |
QString | uiLanguage |
the language to be used for translating user interface strings | |
![]() | |
QString | objectName |
the name of this object | |
Related Symbols | |
(Note that these are not member symbols.) | |
void | qmlRegisterModuleImport (const char *uri, int moduleMajor, const char *import, int importMajor, int importMinor) |
Registers a qmldir-import for module uri of major version moduleMajor. | |
void | qmlUnregisterModuleImport (const char *uri, int moduleMajor, const char *import, int importMajor, int importMinor) |
Removes a module import previously registered with qmlRegisterModuleImport() | |
QQmlEngine * | qmlEngine (const QObject *object) |
Returns the QQmlEngine associated with object, if any. | |
QQmlContext * | qmlContext (const QObject *object) |
Returns the QQmlContext associated with object, if any. | |
![]() | |
QJSEngine * | qjsEngine (const QObject *object) |
![]() | |
template< class T > T | qobject_cast (const QObject *object) |
Returns the given object cast to type T if the object is of type T (or of a subclass); otherwise returns \nullptr. | |
template< typename T > T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
template< typename T > QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QObjectList | |
\macro Q_CLASSINFO(Name, Value) | |
Additional Inherited Members | |
![]() | |
enum | ObjectOwnership { CppOwnership , JavaScriptOwnership } |
ObjectOwnership controls whether or not the JavaScript memory manager automatically destroys the QObject when the corresponding JavaScript object is garbage collected by the engine. More... | |
enum | Extension { TranslationExtension = 0x1 , ConsoleExtension = 0x2 , GarbageCollectionExtension = 0x4 , AllExtensions = 0xffffffff } |
This enum is used to specify extensions to be installed via \l installExtensions(). More... | |
![]() | |
QScopedPointer< QObjectData > | d_ptr |
The QQmlEngine class provides an environment for instantiating QML components.
Each QML component is instantiated in a QQmlContext. QQmlContext's are essential for passing data to QML components. In QML, contexts are arranged hierarchically and this hierarchy is managed by the QQmlEngine.
Prior to creating any QML components, an application must have created a QQmlEngine to gain access to a QML context. The following example shows how to create a simple Text item.
In this case, the Text item will be created in the engine's \l {QQmlEngine::rootContext()}{root context}.
Definition at line 56 of file qqmlengine.h.
Create a new QQmlEngine with the given parent.
Definition at line 608 of file qqmlengine.cpp.
References QJSEnginePrivate::addToDebugServer(), and d.
|
override |
Destroys the QQmlEngine.
Any QQmlContext's created on this engine will be invalidated, but not destroyed (unless they are parented to the QQmlEngine object).
See ~QJSEngine() for details on cleaning up the JS engine.
Definition at line 635 of file qqmlengine.cpp.
References d, QQmlContextPrivate::emitDestruction(), QQmlContextPrivate::get(), QJSEnginePrivate::removeFromDebugServer(), and rootContext().
|
protected |
Definition at line 619 of file qqmlengine.cpp.
References d.
void QQmlEngine::addImageProvider | ( | const QString & | providerId, |
QQmlImageProviderBase * | provider | ||
) |
Sets the provider to use for images requested via the image: url scheme, with host providerId.
The QQmlEngine takes ownership of provider.
Image providers enable support for pixmap and threaded image requests. See the QQuickImageProvider documentation for details on implementing and using image providers.
All required image providers should be added to the engine before any QML sources files are loaded.
Definition at line 927 of file qqmlengine.cpp.
References d, sp, and QString::toLower().
Adds path as a directory where the engine searches for installed modules in a URL-based directory structure.
The path may be a local filesystem directory, a \l {The Qt Resource System}{Qt Resource} path ({
:/imports}), a \l {The Qt Resource System}{Qt Resource} url ({qrc:/imports}
) or a URL.
The path will be converted into canonical form before it is added to the import path list.
The newly added path will be first in the importPathList().
{See also} \l setImportPathList(), \l {QML Modules}, and \l [QtQml] {QML Import Path}
Definition at line 1683 of file qqmlengine.cpp.
References d.
Adds path as a directory where the engine searches for native plugins for imported modules (referenced in the qmldir
file).
By default, the list contains only ., i.e. the engine searches in the directory of the
qmldir
file itself.
The newly added path will be first in the pluginPathList().
Definition at line 1740 of file qqmlengine.cpp.
References d.
void QQmlEngine::addUrlInterceptor | ( | QQmlAbstractUrlInterceptor * | urlInterceptor | ) |
Adds a urlInterceptor to be used when resolving URLs in QML.
This also applies to URLs used for loading script files and QML types. The URL interceptors should not be modifed while the engine is loading files, or URL selection may be inconsistent. Multiple URL interceptors, when given, will be called in the order they were added for each URL.
QQmlEngine does not take ownership of the interceptor and won't delete it.
Definition at line 792 of file qqmlengine.cpp.
References d.
QUrl QQmlEngine::baseUrl | ( | ) | const |
Return the base URL for this engine.
The base URL is only used to resolve components when a relative URL is passed to the QQmlComponent constructor.
If a base URL has not been explicitly set, this method returns the application's current working directory.
Definition at line 972 of file qqmlengine.cpp.
References QDir::currentPath(), d, QUrl::fromLocalFile(), QDir::rootPath(), and QDir::separator().
Referenced by QQmlComponentPrivate::loadUrl(), and QQmlContextData::resolvedUrl().
void QQmlEngine::captureProperty | ( | QObject * | object, |
const QMetaProperty & | property | ||
) | const |
Capture the given property as part of a binding.
Definition at line 1067 of file qqmlengine.cpp.
References d, property, and QMetaObjectPrivate::signalIndex().
Referenced by QV4::QQmlContextWrapper::lookupIdObject().
void QQmlEngine::clearComponentCache | ( | ) |
Clears the engine's internal component cache.
This function causes the property metadata of all components previously loaded by the engine to be destroyed. All previously loaded components and the property bindings for all extant objects created from those components will cease to function.
This function returns the engine to a state where it does not contain any loaded component data. This may be useful in order to reload a smaller subset of the previous component set, or to load a new version of a previously loaded component.
Once the component cache has been cleared, components must be loaded before any new objects can be created.
As a general rule of thumb, make sure that no objects created from QML components are alive when you clear the component cache.
Definition at line 703 of file qqmlengine.cpp.
References d.
void QQmlEngine::clearSingletons | ( | ) |
Clears all singletons the engine owns.
This function drops all singleton instances, deleting any QObjects owned by the engine among them. This is useful to make sure that no QML-created objects are left before calling clearComponentCache().
QML properties holding QObject-based singleton instances become null if the engine owns the singleton or retain their value if the engine doesn't own it. The singletons are not automatically re-created by accessing existing QML-created objects. Only when new components are instantiated, the singletons are re-created.
Definition at line 744 of file qqmlengine.cpp.
References d.
|
static |
Returns the QQmlContext for the object, or nullptr if no context has been set.
When the QQmlEngine instantiates a QObject, an internal context is assigned to it automatically. Such internal contexts are read-only. You cannot set context properties on them.
Definition at line 1201 of file qqmlengine.cpp.
References QQmlData::get().
Referenced by QQuickCanvasItem::componentComplete(), QQuickSelectionRectanglePrivate::createHandle(), QQuickDesignerSupportItems::createPrimitive(), QQuickListViewPrivate::getSectionItem(), QWaylandTextureSharingExtension::initialize(), qmlContext(), QmlJSDebugger::ObjectCreator::tryCreateObject(), QQuickListViewPrivate::updateInlineSection(), and QQuickListViewPrivate::updateStickySections().
|
overrideprotectedvirtual |
\reimp
Reimplemented from QObject.
Definition at line 1241 of file qqmlengine.cpp.
References e, QObject::event(), QEvent::LanguageChange, and retranslate().
|
signal |
This signal is emitted when the QML loaded by the engine would like to exit from the event loop with the specified return code retCode.
Referenced by QQmlApplicationEnginePrivate::init().
QQmlImageProviderBase * QQmlEngine::imageProvider | ( | const QString & | providerId | ) | const |
Returns the image provider set for providerId if found; otherwise returns \nullptr.
Definition at line 941 of file qqmlengine.cpp.
References d, and QString::toLower().
QStringList QQmlEngine::importPathList | ( | ) | const |
Returns the list of directories where the engine searches for installed modules in a URL-based directory structure.
For example, if /opt/MyApp/lib/imports
is in the path, then QML that imports com.mycompany.Feature
will cause the QQmlEngine to look in /opt/MyApp/lib/imports/com/mycompany/Feature/
for the components provided by that module. A qmldir
file is required for defining the type version mapping and possibly QML extensions plugins.
By default, this list contains the paths mentioned in \l {QML Import Path}.
Definition at line 1704 of file qqmlengine.cpp.
References d.
QQmlIncubationController * QQmlEngine::incubationController | ( | ) | const |
Returns the currently set incubation controller, or 0 if no controller has been set.
Definition at line 87 of file qqmlincubator.cpp.
References d.
Referenced by QQuickWidgetPrivate::init(), and QQuickViewPrivate::init().
QUrl QQmlEngine::interceptUrl | ( | const QUrl & | url, |
QQmlAbstractUrlInterceptor::DataType | type | ||
) | const |
Run the current URL interceptors on the given url of the given type and return the result.
Definition at line 816 of file qqmlengine.cpp.
Referenced by QQmlDataBlob::QQmlDataBlob(), QQmlImports::addFileImport(), QQmlImportDatabase::locateLocalQmldir(), QV4Include::method_include(), and QQmlContextData::resolvedUrl().
void QQmlEngine::markCurrentFunctionAsTranslationBinding | ( | ) |
LanguageChange
events. That is a more general mechanism which also works when the class is used in a non-QML context, and has slightly less overhead. However, using markCurrentFunctionAsTranslationBinding
can be acceptable when the class is already closely tied to the QML engine. For more details, see \l {Prepare for Dynamic Language Changes}Definition at line 1055 of file qqmlengine.cpp.
References d.
Returns the file path where a \l{QtQuick.LocalStorage}{Local Storage} database with the identifier databaseName is (or would be) located.
Definition at line 1863 of file qqmlengine.cpp.
References QCryptographicHash::addData(), d, QCryptographicHash::Md5, QCryptographicHash::result(), QByteArray::toHex(), and QString::toUtf8().
QString QQmlEngine::offlineStoragePath | ( | ) | const |
Definition at line 1838 of file qqmlengine.cpp.
References QStandardPaths::AppDataLocation, d, e, QString::isEmpty(), Q_EMIT, QString::replace(), QDir::separator(), and QStandardPaths::writableLocation().
|
signal |
This signal is emitted when \l offlineStoragePath changes.
bool QQmlEngine::outputWarningsToStandardError | ( | ) | const |
Returns true if warning messages will be output to stderr in addition to being emitted by the warnings() signal, otherwise false.
The default value is true.
Definition at line 1001 of file qqmlengine.cpp.
References d.
QStringList QQmlEngine::pluginPathList | ( | ) | const |
Returns the list of directories where the engine searches for native plugins for imported modules (referenced in the qmldir
file).
By default, the list contains only ., i.e. the engine searches in the directory of the
qmldir
file itself.
Definition at line 1755 of file qqmlengine.cpp.
References d.
|
signal |
This signal is emitted when the QML loaded by the engine would like to quit.
Referenced by QQmlApplicationEnginePrivate::init().
Removes the image provider for providerId.
Definition at line 954 of file qqmlengine.cpp.
References d, and QString::toLower().
void QQmlEngine::removeUrlInterceptor | ( | QQmlAbstractUrlInterceptor * | urlInterceptor | ) |
Remove a urlInterceptor that was previously added using \l addUrlInterceptor.
The URL interceptors should not be modifed while the engine is loading files, or URL selection may be inconsistent.
This does not delete the interceptor, but merely removes it from the engine. You can re-use it on the same or a different engine afterwards.
Definition at line 806 of file qqmlengine.cpp.
References d.
|
slot |
Refreshes all binding expressions that use strings marked for translation.
Call this function after you have installed a new translator with QCoreApplication::installTranslator, to ensure that your user-interface shows up-to-date translations.
Definition at line 1185 of file qqmlengine.cpp.
References d.
Referenced by event().
QQmlContext * QQmlEngine::rootContext | ( | ) | const |
Returns the engine's root context.
The root context is automatically created by the QQmlEngine. Data that should be available to all QML component instances instantiated by the engine should be put in the root context.
Additional data that should only be available to a subset of component instances should be added to sub-contexts parented to the root context.
Definition at line 761 of file qqmlengine.cpp.
References d.
Referenced by ~QQmlEngine(), QQmlComponentPrivate::doBeginCreate(), QQmlPropertyPrivate::effectiveContext(), QQmlExpressionPrivate::init(), QQuickViewPrivate::init(), and JavaScriptJob::run().
Set the base URL for this engine to url.
Definition at line 989 of file qqmlengine.cpp.
|
static |
Sets the QQmlContext for the object to context.
If the object already has a context, a warning is output, but the context is not changed.
When the QQmlEngine instantiates a QObject, the context is set automatically.
Definition at line 1221 of file qqmlengine.cpp.
References context, QQmlRefPointer< T >::data(), QQmlData::get(), QQmlContextData::get(), Q_ASSERT, and qWarning.
Referenced by QQuickWindowQmlImpl::classBegin(), QQuickPopup::classBegin(), QQuickRangeSlider::classBegin(), QQuickScrollBar::classBegin(), QQuickSpinBox::classBegin(), QQuickIconLabelPrivate::createImage(), QQuickDesignerSupportItems::createPrimitive(), QuickTestResult::grabImage(), and QQuickViewPrivate::init().
void QQmlEngine::setImportPathList | ( | const QStringList & | paths | ) |
Sets paths as the list of directories where the engine searches for installed modules in a URL-based directory structure.
By default, this list contains the paths mentioned in \l {QML Import Path}.
Definition at line 1722 of file qqmlengine.cpp.
References d.
void QQmlEngine::setIncubationController | ( | QQmlIncubationController * | controller | ) |
Sets the engine's incubation controller.
The engine can only have one active controller and it does not take ownership of it.
Definition at line 73 of file qqmlincubator.cpp.
References d.
Referenced by QQuickWidgetPrivate::ensureEngine(), QQuickWidgetPrivate::init(), and QQuickViewPrivate::init().
Definition at line 1829 of file qqmlengine.cpp.
void QQmlEngine::setOutputWarningsToStandardError | ( | bool | enabled | ) |
Set whether warning messages will be output to stderr to enabled.
If enabled is true, any warning messages generated by QML will be output to stderr and emitted by the warnings() signal. If enabled is false, only the warnings() signal will be emitted. This allows applications to handle warning output themselves.
The default value is true.
Definition at line 1017 of file qqmlengine.cpp.
void QQmlEngine::setPluginPathList | ( | const QStringList & | paths | ) |
Sets the list of directories where the engine searches for native plugins for imported modules (referenced in the qmldir
file) to paths.
By default, the list contains only ., i.e. the engine searches in the directory of the
qmldir
file itself.
Definition at line 1771 of file qqmlengine.cpp.
References d.
QJSValue QQmlEngine::singletonInstance | ( | int | qmlTypeId | ) |
Definition at line 1123 of file qqmlengine.cpp.
References d, QQmlMetaType::qmlTypeById(), and qmlTypeId().
T QQmlEngine::singletonInstance | ( | int | qmlTypeId | ) |
\qmlproperty string Qt::uiLanguage
The uiLanguage holds the name of the language to be used for user interface string translations. It is exposed in C++ as QQmlEngine::uiLanguage property.
You can set the value freely and use it in bindings. It is recommended to set it after installing translators in your application. By convention, an empty string means no translation from the language used in the source code is intended to occur.
If you're using QQmlApplicationEngine and the value changes, QQmlEngine::retranslate() will be called.
Returns the instance of a singleton type that was registered under qmlTypeId.
The template argument T may be either QJSValue or a pointer to a QObject-derived type and depends on how the singleton was registered. If no instance of T has been created yet, it is created now. If qmlTypeId does not represent a valid singleton type, either a default constructed QJSValue or a nullptr
is returned.
QObject* example:
\codeline
\codeline
QJSValue example:
\codeline
It is recommended to store the QML type id, e.g. as a static member in the singleton class. The lookup via qmlTypeId() is costly.
Definition at line 164 of file qqmlengine.h.
References qmlTypeId().
Referenced by QV4::QQmlTypeWrapper::object().
Q_QML_EXPORT QJSValue QQmlEngine::singletonInstance | ( | int | qmlTypeId | ) |
T QQmlEngine::singletonInstance | ( | QAnyStringView | uri, |
QAnyStringView | typeName | ||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Returns the instance of a singleton type named typeName from the module specified by uri.
This method can be used as an alternative to calling qmlTypeId followed by the id based overload of singletonInstance. This is convenient when one only needs to do a one time setup of a singleton; if repeated access to the singleton is required, caching its typeId will allow faster subsequent access via the \l {QQmlEngine::singletonInstance(int qmlTypeId)}{type-id based overload}.
The template argument T may be either QJSValue or a pointer to a QObject-derived type and depends on how the singleton was registered. If no instance of T has been created yet, it is created now. If typeName does not represent a valid singleton type, either a default constructed QJSValue or a nullptr
is returned.
Definition at line 172 of file qqmlengine.h.
References typeName.
QJSValue QQmlEngine::singletonInstance | ( | QAnyStringView | uri, |
QAnyStringView | typeName | ||
) |
Definition at line 1158 of file qqmlengine.cpp.
References d, LoadHelper::ResolveTypeResult::NoSuchModule, and typeName.
Q_QML_EXPORT QJSValue QQmlEngine::singletonInstance | ( | QAnyStringView | uri, |
QAnyStringView | typeName | ||
) |
void QQmlEngine::trimComponentCache | ( | ) |
Trims the engine's internal component cache.
This function causes the property metadata of any loaded components which are not currently in use to be destroyed.
A component is considered to be in use if there are any extant instances of the component itself, any instances of other components that use the component, or any objects instantiated by any of those components.
Definition at line 723 of file qqmlengine.cpp.
References d.
QList< QQmlAbstractUrlInterceptor * > QQmlEngine::urlInterceptors | ( | ) | const |
Returns the list of currently active URL interceptors.
Definition at line 828 of file qqmlengine.cpp.
References d.
Referenced by QQmlImportDatabase::locateLocalQmldir().
This signal is emitted when warnings messages are generated by QML.
|
related |
Returns the QQmlContext associated with object, if any.
This is equivalent to QQmlEngine::contextForObject(object).
{#include <QtQml>} to use this function.Definition at line 71 of file qqml.cpp.
References contextForObject().
|
related |
Returns the QQmlEngine associated with object, if any.
This is equivalent to QQmlEngine::contextForObject(object)->engine(), but more efficient.
{#include <QtQml>} to use this function.Definition at line 76 of file qqml.cpp.
References QQmlData::get().
Referenced by QQmlComponentPrivate::setInitialProperties().
|
related |
Registers a qmldir-import for module uri of major version moduleMajor.
This has the same effect as an import
statement in a qmldir file: Whenever uri of version moduleMajor is imported, import of version importMajor. importMinor is automatically imported, too. If importMajor is \l QQmlModuleImportLatest the latest version available of that module is imported, and importMinor does not matter. If importMinor is \l QQmlModuleImportLatest the latest minor version of a importMajor is chosen. If importMajor is \l QQmlModuleImportAuto the version of import is version of uri being imported, and importMinor does not matter. If moduleMajor is \l QQmlModuleImportModuleAny the module import is applied for any major version of uri. For example, you may specify that whenever any version of MyModule is imported, the latest version of MyOtherModule should be imported. Then, the following call would be appropriate:
Or, you may specify that whenever major version 5 of "MyModule" is imported, then version 3.14 of "MyOtherModule" should be imported:
Finally, if you always want the same version of "MyOtherModule" to be imported whenever "MyModule" is imported, specify the following:
Definition at line 308 of file qqml.cpp.
References QString::fromUtf8(), QQmlMetaType::registerModuleImport(), resolveImport(), and resolveModuleVersion().
|
related |
Removes a module import previously registered with qmlRegisterModuleImport()
Calling this function makes sure that import of version {importMajor}.{importMinor} is not automatically imported anymore when uri of version moduleMajor is. The version resolution works the same way as with \l qmlRegisterModuleImport().
Definition at line 328 of file qqml.cpp.
References QString::fromUtf8(), resolveImport(), resolveModuleVersion(), and QQmlMetaType::unregisterModuleImport().
|
readwrite |
the directory for storing offline user data
Returns the directory where SQL and other offline storage is placed.
The SQL databases created with openDatabaseSync()
are stored here.
The default is QML/OfflineStorage in the platform-standard user application data directory.
Note that the path may not currently exist on the filesystem, so callers wanting to create new files at this location should create it first - see QDir::mkpath().
Definition at line 41 of file qqmlengine.h.
Referenced by QQmlLocalStorage::openDatabaseSync().