The PySide.QtDeclarative.QDeclarativeEngine class provides an environment for instantiating QML components.
Each QML component is instantiated in a PySide.QtDeclarative.QDeclarativeContext . PySide.QtDeclarative.QDeclarativeContext ‘s are essential for passing data to QML components. In QML, contexts are arranged hierarchically and this hierarchy is managed by the PySide.QtDeclarative.QDeclarativeEngine .
Prior to creating any QML components, an application must have created a PySide.QtDeclarative.QDeclarativeEngine to gain access to a QML context. The following example shows how to create a simple Text item.
QDeclarativeEngine engine; QDeclarativeComponent component(&engine); component.setData("import QtQuick 1.0\nText { text: \"Hello world!\" }", QUrl()); QDeclarativeItem *item = qobject_cast<QDeclarativeItem *>(component.create()); //add item to view, etc ...In this case, the Text item will be created in the engine’s root context .
Parameters: | parent – PySide.QtCore.QObject |
---|
Create a new PySide.QtDeclarative.QDeclarativeEngine with the given parent .
Ownership controls whether or not QML automatically destroys the PySide.QtCore.QObject when the object is garbage collected by the JavaScript engine. The two ownership options are:
Constant | Description |
---|---|
QDeclarativeEngine.CppOwnership | The object is owned by C++ code, and will never be deleted by QML. The JavaScript destroy() method cannot be used on objects with CppOwnership . This option is similar to QScriptEngine.QtOwnership . |
QDeclarativeEngine.JavaScriptOwnership | The object is owned by JavaScript. When the object is returned to QML as the return value of a method call or property access, QML will delete the object if there are no remaining JavaScript references to it and it has no QObject.parent() . This option is similar to QScriptEngine.ScriptOwnership . |
Generally an application doesn’t need to set an object’s ownership explicitly. QML uses a heuristic to set the default object ownership. By default, an object that is created by QML has JavaScriptOwnership . The exception to this are the root objects created by calling QDeclarativeCompnent::create() or QDeclarativeComponent.beginCreate() which have CppOwnership by default. The ownership of these root-level objects is considered to have been transferred to the C++ caller.
Objects not-created by QML have CppOwnership by default. The exception to this is objects returned from a C++ method call. The ownership of these objects is passed to JavaScript.
Calling PySide.QtDeclarative.QDeclarativeEngine.setObjectOwnership() overrides the default ownership heuristic used by QML.
Parameters: |
|
---|
Sets the provider to use for images requested via the image : url scheme, with host providerId . The PySide.QtDeclarative.QDeclarativeEngine takes ownership of provider .
Image providers enable support for pixmap and threaded image requests. See the PySide.QtDeclarative.QDeclarativeImageProvider 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.
Parameters: | dir – unicode |
---|
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 or a URL.
The newly added path will be first in the PySide.QtDeclarative.QDeclarativeEngine.importPathList() .
See also
PySide.QtDeclarative.QDeclarativeEngine.setImportPathList() QML Modules
Parameters: | dir – unicode |
---|
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 PySide.QtDeclarative.QDeclarativeEngine.pluginPathList() .
Return type: | PySide.QtCore.QUrl |
---|
Return the base URL for this engine. The base URL is only used to resolve components when a relative URL is passed to the PySide.QtDeclarative.QDeclarativeComponent constructor.
If a base URL has not been explicitly set, this method returns the application’s current working directory.
Clears the engine’s internal component cache.
Normally the PySide.QtDeclarative.QDeclarativeEngine caches components loaded from qml files. This method clears this cache and forces the component to be reloaded.
Parameters: | arg__1 – PySide.QtCore.QObject |
---|---|
Return type: | PySide.QtDeclarative.QDeclarativeContext |
Returns the PySide.QtDeclarative.QDeclarativeContext for the object , or 0 if no context has been set.
When the PySide.QtDeclarative.QDeclarativeEngine instantiates a PySide.QtCore.QObject , the context is set automatically.
Parameters: | id – unicode |
---|---|
Return type: | PySide.QtDeclarative.QDeclarativeImageProvider |
Returns the PySide.QtDeclarative.QDeclarativeImageProvider set for providerId .
Return type: | list of strings |
---|
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 PySide.QtDeclarative.QDeclarativeEngine 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 declarative extensions plugins.
By default, the list contains the directory of the application executable, paths specified in the QML_IMPORT_PATH environment variable, and the builtin ImportsPath from PySide.QtCore.QLibraryInfo .
Parameters: |
|
---|---|
Return type: | (ok, errorString) |
Imports the plugin named filePath with the uri provided. Returns true if the plugin was successfully imported; otherwise returns false.
On failure and if non-null, *``errorString`` will be set to a message describing the failure.
The plugin has to be a Qt plugin which implements the PySide.QtDeclarative.QDeclarativeExtensionPlugin interface.
Return type: | PySide.QtNetwork.QNetworkAccessManager |
---|
Returns a common PySide.QtNetwork.QNetworkAccessManager which can be used by any QML element instantiated by this engine.
If a PySide.QtDeclarative.QDeclarativeNetworkAccessManagerFactory has been set and a PySide.QtNetwork.QNetworkAccessManager has not yet been created, the PySide.QtDeclarative.QDeclarativeNetworkAccessManagerFactory will be used to create the PySide.QtNetwork.QNetworkAccessManager ; otherwise the returned PySide.QtNetwork.QNetworkAccessManager will have no proxy or cache set.
Return type: | PySide.QtDeclarative.QDeclarativeNetworkAccessManagerFactory |
---|
Returns the current PySide.QtDeclarative.QDeclarativeNetworkAccessManagerFactory .
Parameters: | arg__1 – PySide.QtCore.QObject |
---|---|
Return type: | PySide.QtDeclarative.QDeclarativeEngine.ObjectOwnership |
Returns the ownership of object .
Return type: | unicode |
---|
This property holds the directory for storing offline user data.
Returns the directory where SQL and other offline storage is placed.
QDeclarativeWebView and the SQL databases created with openDatabase() 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() .
Return type: | PySide.QtCore.bool |
---|
Returns true if warning messages will be output to stderr in addition to being emitted by the PySide.QtDeclarative.QDeclarativeEngine.warnings() signal, otherwise false.
The default value is true.
Return type: | list of strings |
---|
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.
Parameters: | id – unicode |
---|
Removes the PySide.QtDeclarative.QDeclarativeImageProvider for providerId .
Returns the provider if it was found; otherwise returns 0.
Return type: | PySide.QtDeclarative.QDeclarativeContext |
---|
Returns the engine’s root context.
The root context is automatically created by the PySide.QtDeclarative.QDeclarativeEngine . 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.
Parameters: | arg__1 – PySide.QtCore.QUrl |
---|
Set the base URL for this engine to url .
Parameters: |
|
---|
Sets the PySide.QtDeclarative.QDeclarativeContext for the object to context . If the object already has a context, a warning is output, but the context is not changed.
When the PySide.QtDeclarative.QDeclarativeEngine instantiates a PySide.QtCore.QObject , the context is set automatically.
Parameters: | paths – list of strings |
---|
Sets paths as the list of directories where the engine searches for installed modules in a URL-based directory structure.
By default, the list contains the directory of the application executable, paths specified in the QML_IMPORT_PATH environment variable, and the builtin ImportsPath from PySide.QtCore.QLibraryInfo .
Parameters: | arg__1 – PySide.QtDeclarative.QDeclarativeNetworkAccessManagerFactory |
---|
Sets the factory to use for creating PySide.QtNetwork.QNetworkAccessManager (s).
PySide.QtNetwork.QNetworkAccessManager is used for all network access by QML. By implementing a factory it is possible to create custom PySide.QtNetwork.QNetworkAccessManager with specialized caching, proxy and cookie support.
The factory must be set before executing the engine.
Parameters: |
|
---|
Sets the ownership of object .
Parameters: | dir – unicode |
---|
This property holds the directory for storing offline user data.
Returns the directory where SQL and other offline storage is placed.
QDeclarativeWebView and the SQL databases created with openDatabase() 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() .
Parameters: | arg__1 – PySide.QtCore.bool |
---|
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 PySide.QtDeclarative.QDeclarativeEngine.warnings() signal. If enabled is false, on the PySide.QtDeclarative.QDeclarativeEngine.warnings() signal will be emitted. This allows applications to handle warning output themselves.
The default value is true.
Parameters: | paths – list of strings |
---|
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.
Parameters: | warnings – |
---|