![]() |
Home · All Classes · All Functions · Overviews |
The QDeclarativeEngine class provides an environment for instantiating QML components. More...
#include <QDeclarativeEngine>
Inherits QObject.
This class was introduced in Qt 4.7.
QDeclarativeEngine ( QObject * parent = 0 ) | |
virtual | ~QDeclarativeEngine () |
void | addImageProvider ( const QString & providerId, QDeclarativeImageProvider * provider ) |
void | addImportPath ( const QString & path ) |
QUrl | baseUrl () const |
void | clearComponentCache () |
QDeclarativeImageProvider * | imageProvider ( const QString & providerId ) const |
bool | importExtension ( const QString & fileName, const QString & uri ) |
QNetworkAccessManager * | networkAccessManager () const |
QDeclarativeNetworkAccessManagerFactory * | networkAccessManagerFactory () const |
QString | offlineStoragePath () const |
void | removeImageProvider ( const QString & providerId ) |
QDeclarativeContext * | rootContext () |
void | setBaseUrl ( const QUrl & url ) |
void | setNetworkAccessManagerFactory ( QDeclarativeNetworkAccessManagerFactory * factory ) |
void | setOfflineStoragePath ( const QString & dir ) |
void | quit () |
QDeclarativeContext * | contextForObject ( const QObject * object ) |
void | setContextForObject ( QObject * object, QDeclarativeContext * context ) |
The QDeclarativeEngine class provides an environment for instantiating QML components.
Each QML component is instantiated in a QDeclarativeContext. QDeclarativeContext's are essential for passing data to QML components. In QML, contexts are arranged hierarchically and this hierarchy is managed by the QDeclarativeEngine.
Prior to creating any QML components, an application must have created a 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 Qt 4.6\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.
See also QDeclarativeComponent and QDeclarativeContext.
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().
Access functions:
QString | offlineStoragePath () const |
void | setOfflineStoragePath ( const QString & dir ) |
Create a new QDeclarativeEngine with the given parent.
Destroys the QDeclarativeEngine.
Any QDeclarativeContext's created on this engine will be invalidated, but not destroyed (unless they are parented to the QDeclarativeEngine object).
Sets the provider to use for images requested via the image: url scheme, with host providerId.
QDeclarativeImageProvider allows images to be provided to QML asynchronously. The image request will be run in a low priority thread. This allows potentially costly image loading to be done in the background, without affecting the performance of the UI.
Note that images loaded from a QDeclarativeImageProvider are cached by QPixmapCache, similar to any image loaded by QML.
The QDeclarativeEngine assumes ownership of the provider.
This example creates a provider with id colors:
See also removeImageProvider().
Adds path as a directory where installed QML components are defined in a URL-based directory structure.
For example, if you add /opt/MyApp/lib/imports and then load QML that imports com.mycompany.Feature, then QDeclarativeEngine will look in /opt/MyApp/lib/imports/com/mycompany/Feature/ for the components provided by that module. A qmldir file is required for definiting the type version mapping and possibly declarative extensions plugins.
The engine searches in the base directory of the qml file, then the paths added via addImportPath(), then the paths specified in the QML_IMPORT_PATH environment variable, then the builtin ImportsPath from QLibraryInfo.
Return the base URL for this engine. The base URL is only used to resolve components when a relative URL is passed to the QDeclarativeComponent constructor.
If a base URL has not been explicitly set, this method returns the application's current working directory.
See also setBaseUrl().
Clears the engine's internal component cache.
Normally the QDeclarativeEngine caches components loaded from qml files. This method clears this cache and forces the component to be reloaded.
Returns the QDeclarativeContext for the object, or 0 if no context has been set.
When the QDeclarativeEngine instantiates a QObject, the context is set automatically.
See also setContextForObject().
Returns the QDeclarativeImageProvider set for providerId.
Imports the given extension into this QDeclarativeEngine. Returns true if the extension was successfully imported.
See also QDeclarativeExtensionInterface.
Returns a common QNetworkAccessManager which can be used by any QML element instantiated by this engine.
If a QDeclarativeNetworkAccessManagerFactory has been set and a QNetworkAccessManager has not yet been created, the QDeclarativeNetworkAccessManagerFactory will be used to create the QNetworkAccessManager; otherwise the returned QNetworkAccessManager will have no proxy or cache set.
See also setNetworkAccessManagerFactory().
Returns the current QDeclarativeNetworkAccessManagerFactory.
See also setNetworkAccessManagerFactory().
This signal is emitted when the QDeclarativeEngine quits.
Removes the QDeclarativeImageProvider for providerId.
Returns the provider if it was found; otherwise returns 0.
See also addImageProvider().
Returns the engine's root context.
The root context is automatically created by the 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.
Set the base URL for this engine to url.
See also baseUrl().
Sets the 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 QDeclarativeEngine instantiates a QObject, the context is set automatically.
See also contextForObject().
Sets the factory to use for creating QNetworkAccessManager(s).
QNetworkAccessManager is used for all network access by QML. By implementing a factory it is possible to create custom QNetworkAccessManager with specialized caching, proxy and cookie support.
The factory must be set before exceuting the engine.
See also networkAccessManagerFactory().
Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies) | Trademarks | Qt 4.7.0 |