Qt 4.8
|
The QDeclarativeEngine class provides an environment for instantiating QML components. More...
#include <qdeclarativeengine.h>
Public Types | |
enum | ObjectOwnership { CppOwnership, JavaScriptOwnership } |
Ownership controls whether or not QML automatically destroys the QObject when the object is garbage collected by the JavaScript engine. More... | |
Signals | |
void | quit () |
This signal is emitted when the QML loaded by the engine would like to quit. More... | |
void | warnings (const QList< QDeclarativeError > &warnings) |
This signal is emitted when warnings messages are generated by QML. More... | |
Signals inherited from QObject | |
void | destroyed (QObject *=0) |
This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More... | |
Public Functions | |
void | addImageProvider (const QString &id, QDeclarativeImageProvider *) |
Sets the provider to use for images requested via the image: url scheme, with host providerId. More... | |
void | addImportPath (const QString &dir) |
Adds path as a directory where the engine searches for installed modules in a URL-based directory structure. More... | |
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). More... | |
QUrl | baseUrl () const |
Return the base URL for this engine. More... | |
void | clearComponentCache () |
Clears the engine's internal component cache. More... | |
QDeclarativeImageProvider * | imageProvider (const QString &id) const |
Returns the QDeclarativeImageProvider set for providerId. More... | |
QStringList | importPathList () const |
Returns the list of directories where the engine searches for installed modules in a URL-based directory structure. More... | |
bool | importPlugin (const QString &filePath, const QString &uri, QString *errorString) |
Imports the plugin named filePath with the uri provided. More... | |
QNetworkAccessManager * | networkAccessManager () const |
Returns a common QNetworkAccessManager which can be used by any QML element instantiated by this engine. More... | |
QDeclarativeNetworkAccessManagerFactory * | networkAccessManagerFactory () const |
Returns the current QDeclarativeNetworkAccessManagerFactory. More... | |
QString | offlineStoragePath () const |
bool | outputWarningsToStandardError () const |
Returns true if warning messages will be output to stderr in addition to being emitted by the warnings() signal, otherwise false. More... | |
QStringList | pluginPathList () const |
Returns the list of directories where the engine searches for native plugins for imported modules (referenced in the qmldir file). More... | |
QDeclarativeEngine (QObject *p=0) | |
Create a new QDeclarativeEngine with the given parent. More... | |
void | removeImageProvider (const QString &id) |
Removes the QDeclarativeImageProvider for providerId. More... | |
QDeclarativeContext * | rootContext () const |
Returns the engine's root context. More... | |
void | setBaseUrl (const QUrl &) |
Set the base URL for this engine to url. More... | |
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. More... | |
void | setNetworkAccessManagerFactory (QDeclarativeNetworkAccessManagerFactory *) |
Sets the factory to use for creating QNetworkAccessManager(s). More... | |
void | setOfflineStoragePath (const QString &dir) |
void | setOutputWarningsToStandardError (bool) |
Set whether warning messages will be output to stderr to enabled. More... | |
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. More... | |
virtual | ~QDeclarativeEngine () |
Destroys the QDeclarativeEngine. More... | |
Public Functions inherited from QObject | |
bool | blockSignals (bool b) |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More... | |
const QObjectList & | children () const |
Returns a list of child objects. More... | |
bool | connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const |
bool | disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0) |
bool | disconnect (const QObject *receiver, const char *member=0) |
void | dumpObjectInfo () |
Dumps information about signal connections, etc. More... | |
void | dumpObjectTree () |
Dumps a tree of children to the debug output. More... | |
QList< QByteArray > | dynamicPropertyNames () const |
Returns the names of all properties that were dynamically added to the object using setProperty(). More... | |
virtual bool | event (QEvent *) |
This virtual function receives events to an object and should return true if the event e was recognized and processed. More... | |
virtual bool | eventFilter (QObject *, QEvent *) |
Filters events if this object has been installed as an event filter for the watched object. More... | |
template<typename T > | |
T | findChild (const QString &aName=QString()) const |
Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More... | |
template<typename T > | |
QList< T > | findChildren (const QString &aName=QString()) 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. More... | |
template<typename T > | |
QList< T > | findChildren (const QRegExp &re) const |
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. More... | |
void | installEventFilter (QObject *) |
Installs an event filter filterObj on this object. More... | |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false. More... | |
void | killTimer (int id) |
Kills the timer with timer identifier, id. More... | |
virtual const QMetaObject * | metaObject () const |
Returns a pointer to the meta-object of this object. More... | |
void | moveToThread (QThread *thread) |
Changes the thread affinity for this object and its children. More... | |
QString | objectName () const |
QObject * | parent () const |
Returns a pointer to the parent object. More... | |
QVariant | property (const char *name) const |
Returns the value of the object's name property. More... | |
Q_INVOKABLE | QObject (QObject *parent=0) |
Constructs an object with parent object parent. More... | |
void | removeEventFilter (QObject *) |
Removes an event filter object obj from this object. More... | |
void | setObjectName (const QString &name) |
void | setParent (QObject *) |
Makes the object a child of parent. More... | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. More... | |
void | setUserData (uint id, QObjectUserData *data) |
bool | signalsBlocked () const |
Returns true if signals are blocked; otherwise returns false. More... | |
int | startTimer (int interval) |
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More... | |
QThread * | thread () const |
Returns the thread in which the object lives. More... | |
QObjectUserData * | userData (uint id) const |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. More... | |
Static Public Functions | |
static QDeclarativeContext * | contextForObject (const QObject *) |
Returns the QDeclarativeContext for the object, or 0 if no context has been set. More... | |
static ObjectOwnership | objectOwnership (QObject *) |
Returns the ownership of object. More... | |
static void | setContextForObject (QObject *, QDeclarativeContext *) |
Sets the QDeclarativeContext for the object to context. More... | |
static void | setObjectOwnership (QObject *, ObjectOwnership) |
Sets the ownership of object. More... | |
Static Public Functions inherited from QObject | |
static bool | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More... | |
static bool | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
Disconnects signal in object sender from method in object receiver. More... | |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static uint | registerUserData () |
static QString | tr (const char *sourceText, const char *comment=0, int n=-1) |
static QString | trUtf8 (const char *sourceText, const char *comment=0, int n=-1) |
Properties | |
QString | offlineStoragePath |
the directory for storing offline user data More... | |
Related Functions | |
(Note that these are not member functions.) | |
QDeclarativeInfo | qmlInfo (const QObject *object) |
int | qmlRegisterType (const char *url, const char *uri, int versionMajor, int versionMinor, const char *qmlName) |
int | qmlRegisterUncreatableType (const char *url, const char *uri, int versionMajor, int versionMinor, const char *qmlName) |
Related Functions inherited from QObject | |
T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QRegExp ®Exp)() |
T * | qobject_cast (QObject *object) |
QObjectList | |
void * | qt_find_obj_child (QObject *parent, const char *type, const QString &name) |
Returns a pointer to the object named name that inherits type and with a given parent. More... | |
Additional Inherited Members | |
Public Slots inherited from QObject | |
void | deleteLater () |
Schedules this object for deletion. More... | |
Static Public Variables inherited from QObject | |
static const QMetaObject | staticMetaObject |
This variable stores the meta-object for the class. More... | |
Protected Functions inherited from QObject | |
virtual void | childEvent (QChildEvent *) |
This event handler can be reimplemented in a subclass to receive child events. More... | |
virtual void | connectNotify (const char *signal) |
This virtual function is called when something has been connected to signal in this object. More... | |
virtual void | customEvent (QEvent *) |
This event handler can be reimplemented in a subclass to receive custom events. More... | |
virtual void | disconnectNotify (const char *signal) |
This virtual function is called when something has been disconnected from signal in this object. More... | |
QObject (QObjectPrivate &dd, QObject *parent=0) | |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. More... | |
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 0. More... | |
int | senderSignalIndex () const |
virtual void | timerEvent (QTimerEvent *) |
This event handler can be reimplemented in a subclass to receive timer events for the object. More... | |
Protected Variables inherited from QObject | |
QScopedPointer< QObjectData > | d_ptr |
Static Protected Variables inherited from QObject | |
static const QMetaObject | staticQtMetaObject |
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.
In this case, the Text item will be created in the engine's QDeclarativeEngine::rootContext(){root context}.
Definition at line 70 of file qdeclarativeengine.h.
Ownership controls whether or not QML automatically destroys the QObject when the object is garbage collected by the JavaScript engine.
The two ownership options are:
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 setObjectOwnership() overrides the default ownership heuristic used by QML.
Enumerator | |
---|---|
CppOwnership | |
JavaScriptOwnership |
Definition at line 113 of file qdeclarativeengine.h.
QDeclarativeEngine::QDeclarativeEngine | ( | QObject * | p = 0 | ) |
Create a new QDeclarativeEngine with the given parent.
Definition at line 654 of file qdeclarativeengine.cpp.
|
virtual |
Destroys the QDeclarativeEngine.
Any QDeclarativeContext's created on this engine will be invalidated, but not destroyed (unless they are parented to the QDeclarativeEngine object).
Definition at line 668 of file qdeclarativeengine.cpp.
void QDeclarativeEngine::addImageProvider | ( | const QString & | providerId, |
QDeclarativeImageProvider * | provider | ||
) |
Sets the provider to use for images requested via the image: url scheme, with host providerId.
The QDeclarativeEngine takes ownership of provider.
Image providers enable support for pixmap and threaded image requests. See the 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.
Definition at line 803 of file qdeclarativeengine.cpp.
void QDeclarativeEngine::addImportPath | ( | const QString & | path | ) |
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 importPathList().
Definition at line 2196 of file qdeclarativeengine.cpp.
Referenced by QmlApplicationViewer::addImportPath().
void QDeclarativeEngine::addPluginPath | ( | const QString & | path | ) |
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 2252 of file qdeclarativeengine.cpp.
QUrl QDeclarativeEngine::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 QDeclarativeComponent constructor.
If a base URL has not been explicitly set, this method returns the application's current working directory.
Definition at line 880 of file qdeclarativeengine.cpp.
Referenced by QDeclarativeContextData::resolvedUrl().
void QDeclarativeEngine::clearComponentCache | ( | ) |
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.
Definition at line 698 of file qdeclarativeengine.cpp.
Referenced by QmlJSDebugger::AbstractViewInspector::clearComponentCache().
|
static |
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.
Definition at line 936 of file qdeclarativeengine.cpp.
Referenced by QmlJSDebugger::AbstractViewInspector::createQmlObject(), QDeclarativeListViewPrivate::createSection(), QDeclarativeVisualDataModel::indexOf(), ModelNode::model(), qmlContext(), qmlEngine(), and QDeclarativeVisualItemModel::stringValue().
QDeclarativeImageProvider * QDeclarativeEngine::imageProvider | ( | const QString & | id | ) | const |
Returns the QDeclarativeImageProvider set for providerId.
Definition at line 813 of file qdeclarativeengine.cpp.
QStringList QDeclarativeEngine::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 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 QLibraryInfo.
Definition at line 2218 of file qdeclarativeengine.cpp.
bool QDeclarativeEngine::importPlugin | ( | const QString & | filePath, |
const QString & | uri, | ||
QString * | 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 QDeclarativeExtensionPlugin interface.
Definition at line 2299 of file qdeclarativeengine.cpp.
QNetworkAccessManager * QDeclarativeEngine::networkAccessManager | ( | ) | const |
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.
Definition at line 782 of file qdeclarativeengine.cpp.
Referenced by QDeclarativeEnginePrivate::getNetworkAccessManager(), QDeclarativeBorderImage::load(), QDeclarativeAnimatedImage::load(), QDeclarativeDataLoader::load(), QDeclarativeDataLoader::networkReplyFinished(), and QDeclarativeXmlListModel::reload().
QDeclarativeNetworkAccessManagerFactory * QDeclarativeEngine::networkAccessManagerFactory | ( | ) | const |
Returns the current QDeclarativeNetworkAccessManagerFactory.
Definition at line 743 of file qdeclarativeengine.cpp.
Referenced by QDeclarativeEnginePrivate::createNetworkAccessManager(), and QDeclarativeWorkerScriptEnginePrivate::ScriptEngine::networkAccessManager().
|
static |
Returns the ownership of object.
Definition at line 1035 of file qdeclarativeengine.cpp.
QString QDeclarativeEngine::offlineStoragePath | ( | ) | const |
Referenced by setOfflineStoragePath().
bool QDeclarativeEngine::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 907 of file qdeclarativeengine.cpp.
QStringList QDeclarativeEngine::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 2268 of file qdeclarativeengine.cpp.
|
signal |
This signal is emitted when the QML loaded by the engine would like to quit.
Referenced by QDeclarativeEnginePrivate::sendQuit().
void QDeclarativeEngine::removeImageProvider | ( | const QString & | providerId | ) |
Removes the QDeclarativeImageProvider for providerId.
Returns the provider if it was found; otherwise returns 0.
Definition at line 827 of file qdeclarativeengine.cpp.
QDeclarativeContext * QDeclarativeEngine::rootContext | ( | ) | const |
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.
Definition at line 715 of file qdeclarativeengine.cpp.
Referenced by QDeclarativeEngineDebugService::messageReceived(), and QDeclarativeContext::QDeclarativeContext().
void QDeclarativeEngine::setBaseUrl | ( | const QUrl & | url | ) |
Set the base URL for this engine to url.
Definition at line 895 of file qdeclarativeengine.cpp.
|
static |
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.
Definition at line 962 of file qdeclarativeengine.cpp.
Referenced by ModelNode::model().
void QDeclarativeEngine::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, the list contains the directory of the application executable, paths specified in the QML_IMPORT_PATH
environment variable, and the builtin ImportsPath
from QLibraryInfo.
Definition at line 2234 of file qdeclarativeengine.cpp.
void QDeclarativeEngine::setNetworkAccessManagerFactory | ( | QDeclarativeNetworkAccessManagerFactory * | factory | ) |
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 executing the engine.
Definition at line 731 of file qdeclarativeengine.cpp.
|
static |
Sets the ownership of object.
Definition at line 1019 of file qdeclarativeengine.cpp.
void QDeclarativeEngine::setOfflineStoragePath | ( | const QString & | dir | ) |
Definition at line 2325 of file qdeclarativeengine.cpp.
Referenced by main().
void QDeclarativeEngine::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, on the warnings() signal will be emitted. This allows applications to handle warning output themselves.
The default value is true.
Definition at line 923 of file qdeclarativeengine.cpp.
void QDeclarativeEngine::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 2284 of file qdeclarativeengine.cpp.
|
signal |
This signal is emitted when warnings messages are generated by QML.
|
related |
Prints warning messages that include the file and line number for the specified QML object.
When QML types display warning messages, it improves traceability if they include the QML file and line number on which the particular instance was instantiated.
To include the file and line number, an object must be passed. If the file and line number is not available for that instance (either it was not instantiated by the QML engine or location information is disabled), "unknown location" will be used instead.
For example,
prints
Definition at line 155 of file qdeclarativeinfo.cpp.
|
related |
This function registers a type in the QML system with the name qmlName, in the library imported from uri having the version number composed from versionMajor and versionMinor. The type is defined by the QML file located at url.
Normally QML files can be loaded as types directly from other QML files, or using a qmldir file. This function allows registration of files to types from a C++ module, such as when the type mapping needs to be procedurally determined at startup.
Returns non-zero if the registration was sucessful.
This function is added to QtQuick 1 in Qt 5, and is here as private API for developers needing compatibility.
|
related |
This overload is backported from Qt5, and allows uncreatable types to be versioned.
|
private |
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().
Definition at line 72 of file qdeclarativeengine.h.