Qt 4.8
Public Types | Signals | Public Functions | Static Public Functions | Properties | Related Functions | List of all members
QDeclarativeEngine Class Reference

The QDeclarativeEngine class provides an environment for instantiating QML components. More...

#include <qdeclarativeengine.h>

Inheritance diagram for QDeclarativeEngine:
QObject

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...
 
QDeclarativeImageProviderimageProvider (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...
 
QNetworkAccessManagernetworkAccessManager () const
 Returns a common QNetworkAccessManager which can be used by any QML element instantiated by this engine. More...
 
QDeclarativeNetworkAccessManagerFactorynetworkAccessManagerFactory () 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...
 
QDeclarativeContextrootContext () 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 QObjectListchildren () 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< QByteArraydynamicPropertyNames () 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 >
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 QMetaObjectmetaObject () 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
 
QObjectparent () 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...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Static Public Functions

static QDeclarativeContextcontextForObject (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)
 

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...
 
QObjectsender () 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< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

The QDeclarativeEngine class provides an environment for instantiating QML components.

Since
4.7

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.

component.setData("import QtQuick 1.0\nText { text: \"Hello world!\" }", QUrl());
//add item to view, etc
...

In this case, the Text item will be created in the engine's QDeclarativeEngine::rootContext(){root context}.

See also
QDeclarativeComponent QDeclarativeContext

Definition at line 70 of file qdeclarativeengine.h.

Enumerations

◆ ObjectOwnership

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:

  • 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.
  • 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 setObjectOwnership() overrides the default ownership heuristic used by QML.

Enumerator
CppOwnership 
JavaScriptOwnership 

Definition at line 113 of file qdeclarativeengine.h.

Constructors and Destructors

◆ QDeclarativeEngine()

QDeclarativeEngine::QDeclarativeEngine ( QObject p = 0)

Create a new QDeclarativeEngine with the given parent.

Definition at line 654 of file qdeclarativeengine.cpp.

656 {
658  d->init();
659 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDeclarativeEngine class provides an environment for instantiating QML components.
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273

◆ ~QDeclarativeEngine()

QDeclarativeEngine::~QDeclarativeEngine ( )
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.

669 {
671  if (d->isDebugging) {
674  }
675 }
double d
Definition: qnumeric_p.h:62
void removeEngine(QDeclarativeEngine *)
#define Q_D(Class)
Definition: qglobal.h:2482
The QDeclarativeEngine class provides an environment for instantiating QML components.
static QDeclarativeEngineDebugService * instance()
static QJSDebugService * instance()

Functions

◆ addImageProvider()

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.

See also
removeImageProvider()

Definition at line 803 of file qdeclarativeengine.cpp.

804 {
806  QMutexLocker locker(&d->mutex);
807  d->imageProviders.insert(providerId.toLower(), QSharedPointer<QDeclarativeImageProvider>(provider));
808 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
The QDeclarativeEngine class provides an environment for instantiating QML components.
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389

◆ addImportPath()

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().

See also
setImportPathList(), {QML Modules}

Definition at line 2196 of file qdeclarativeengine.cpp.

Referenced by QmlApplicationViewer::addImportPath().

2197 {
2199  d->importDatabase.addImportPath(path);
2200 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDeclarativeEngine class provides an environment for instantiating QML components.

◆ addPluginPath()

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().

See also
setPluginPathList()

Definition at line 2252 of file qdeclarativeengine.cpp.

2253 {
2255  d->importDatabase.addPluginPath(path);
2256 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDeclarativeEngine class provides an environment for instantiating QML components.

◆ baseUrl()

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.

See also
setBaseUrl()

Definition at line 880 of file qdeclarativeengine.cpp.

Referenced by QDeclarativeContextData::resolvedUrl().

881 {
882  Q_D(const QDeclarativeEngine);
883  if (d->baseUrl.isEmpty()) {
885  } else {
886  return d->baseUrl;
887  }
888 }
double d
Definition: qnumeric_p.h:62
static QString currentPath()
Returns the absolute path of the application&#39;s current directory.
Definition: qdir.cpp:1875
#define Q_D(Class)
Definition: qglobal.h:2482
static QChar separator()
Returns the native directory separator: "/" under Unix (including Mac OS X) and "\\" under Windows...
Definition: qdir.cpp:1831
The QDeclarativeEngine class provides an environment for instantiating QML components.
static QUrl fromLocalFile(const QString &localfile)
Returns a QUrl representation of localFile, interpreted as a local file.
Definition: qurl.cpp:6374

◆ clearComponentCache()

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().

699 {
701  d->typeLoader.clearCache();
702 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDeclarativeEngine class provides an environment for instantiating QML components.

◆ contextForObject()

QDeclarativeContext * QDeclarativeEngine::contextForObject ( const QObject object)
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().

937 {
938  if(!object)
939  return 0;
940 
941  QObjectPrivate *priv = QObjectPrivate::get(const_cast<QObject *>(object));
942 
944  static_cast<QDeclarativeData *>(priv->declarativeData);
945 
946  if (!data)
947  return 0;
948  else if (data->outerContext)
949  return data->outerContext->asQDeclarativeContext();
950  else
951  return 0;
952 }
QDeclarativeContextData * outerContext
static QObjectPrivate * get(QObject *o)
Definition: qobject_p.h:177
static const char * data(const QByteArray &arr)
QAbstractDeclarativeData * declarativeData
Definition: qobject_p.h:214
QDeclarativeContext * asQDeclarativeContext()
static const QMetaObjectPrivate * priv(const uint *data)

◆ imageProvider()

QDeclarativeImageProvider * QDeclarativeEngine::imageProvider ( const QString id) const

Returns the QDeclarativeImageProvider set for providerId.

Definition at line 813 of file qdeclarativeengine.cpp.

814 {
815  Q_D(const QDeclarativeEngine);
816  QMutexLocker locker(&d->mutex);
817  return d->imageProviders.value(providerId).data();
818 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
The QDeclarativeEngine class provides an environment for instantiating QML components.

◆ importPathList()

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.

See also
addImportPath() setImportPathList()

Definition at line 2218 of file qdeclarativeengine.cpp.

2219 {
2220  Q_D(const QDeclarativeEngine);
2221  return d->importDatabase.importPathList();
2222 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDeclarativeEngine class provides an environment for instantiating QML components.

◆ importPlugin()

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.

2300 {
2302  return d->importDatabase.importPlugin(filePath, uri, errorString);
2303 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDeclarativeEngine class provides an environment for instantiating QML components.

◆ networkAccessManager()

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.

See also
setNetworkAccessManagerFactory()

Definition at line 782 of file qdeclarativeengine.cpp.

Referenced by QDeclarativeEnginePrivate::getNetworkAccessManager(), QDeclarativeBorderImage::load(), QDeclarativeAnimatedImage::load(), QDeclarativeDataLoader::load(), QDeclarativeDataLoader::networkReplyFinished(), and QDeclarativeXmlListModel::reload().

783 {
784  Q_D(const QDeclarativeEngine);
785  return d->getNetworkAccessManager();
786 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDeclarativeEngine class provides an environment for instantiating QML components.

◆ networkAccessManagerFactory()

QDeclarativeNetworkAccessManagerFactory * QDeclarativeEngine::networkAccessManagerFactory ( ) const

Returns the current QDeclarativeNetworkAccessManagerFactory.

See also
setNetworkAccessManagerFactory()

Definition at line 743 of file qdeclarativeengine.cpp.

Referenced by QDeclarativeEnginePrivate::createNetworkAccessManager(), and QDeclarativeWorkerScriptEnginePrivate::ScriptEngine::networkAccessManager().

744 {
745  Q_D(const QDeclarativeEngine);
746  return d->networkAccessManagerFactory;
747 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDeclarativeEngine class provides an environment for instantiating QML components.

◆ objectOwnership()

QDeclarativeEngine::ObjectOwnership QDeclarativeEngine::objectOwnership ( QObject object)
static

Returns the ownership of object.

Definition at line 1035 of file qdeclarativeengine.cpp.

1036 {
1037  if (!object)
1038  return CppOwnership;
1039 
1040  QDeclarativeData *ddata = QDeclarativeData::get(object, false);
1041  if (!ddata)
1042  return CppOwnership;
1043  else
1045 }
static QDeclarativeData * get(const QObject *object, bool create=false)

◆ offlineStoragePath()

QString QDeclarativeEngine::offlineStoragePath ( ) const

Referenced by setOfflineStoragePath().

◆ outputWarningsToStandardError()

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.

908 {
909  Q_D(const QDeclarativeEngine);
910  return d->outputWarningsToStdErr;
911 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDeclarativeEngine class provides an environment for instantiating QML components.

◆ pluginPathList()

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.

See also
addPluginPath() setPluginPathList()

Definition at line 2268 of file qdeclarativeengine.cpp.

2269 {
2270  Q_D(const QDeclarativeEngine);
2271  return d->importDatabase.pluginPathList();
2272 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDeclarativeEngine class provides an environment for instantiating QML components.

◆ quit

void QDeclarativeEngine::quit ( )
signal

This signal is emitted when the QML loaded by the engine would like to quit.

Referenced by QDeclarativeEnginePrivate::sendQuit().

◆ removeImageProvider()

void QDeclarativeEngine::removeImageProvider ( const QString providerId)

Removes the QDeclarativeImageProvider for providerId.

Returns the provider if it was found; otherwise returns 0.

See also
addImageProvider()

Definition at line 827 of file qdeclarativeengine.cpp.

828 {
830  QMutexLocker locker(&d->mutex);
831  d->imageProviders.take(providerId);
832 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
The QDeclarativeEngine class provides an environment for instantiating QML components.

◆ rootContext()

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().

716 {
717  Q_D(const QDeclarativeEngine);
718  return d->rootContext;
719 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDeclarativeEngine class provides an environment for instantiating QML components.

◆ setBaseUrl()

void QDeclarativeEngine::setBaseUrl ( const QUrl url)

Set the base URL for this engine to url.

See also
baseUrl()

Definition at line 895 of file qdeclarativeengine.cpp.

896 {
898  d->baseUrl = url;
899 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDeclarativeEngine class provides an environment for instantiating QML components.

◆ setContextForObject()

void QDeclarativeEngine::setContextForObject ( QObject object,
QDeclarativeContext context 
)
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().

963 {
964  if (!object || !context)
965  return;
966 
968  if (data->context) {
969  qWarning("QDeclarativeEngine::setContextForObject(): Object already has a QDeclarativeContext");
970  return;
971  }
972 
974  contextData->addObject(object);
975 }
QDeclarativeContextData * context
static QDeclarativeData * get(const QObject *object, bool create=false)
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
static QDeclarativeContextData * get(QDeclarativeContext *context)

◆ setImportPathList()

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.

See also
importPathList() addImportPath()

Definition at line 2234 of file qdeclarativeengine.cpp.

2235 {
2237  d->importDatabase.setImportPathList(paths);
2238 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDeclarativeEngine class provides an environment for instantiating QML components.

◆ setNetworkAccessManagerFactory()

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.

732 {
734  QMutexLocker locker(&d->mutex);
735  d->networkAccessManagerFactory = factory;
736 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
The QDeclarativeEngine class provides an environment for instantiating QML components.

◆ setObjectOwnership()

void QDeclarativeEngine::setObjectOwnership ( QObject object,
ObjectOwnership  ownership 
)
static

Sets the ownership of object.

Definition at line 1019 of file qdeclarativeengine.cpp.

1020 {
1021  if (!object)
1022  return;
1023 
1024  QDeclarativeData *ddata = QDeclarativeData::get(object, true);
1025  if (!ddata)
1026  return;
1027 
1028  ddata->indestructible = (ownership == CppOwnership)?true:false;
1029  ddata->explicitIndestructibleSet = true;
1030 }
static QDeclarativeData * get(const QObject *object, bool create=false)
quint32 explicitIndestructibleSet

◆ setOfflineStoragePath()

void QDeclarativeEngine::setOfflineStoragePath ( const QString dir)

Definition at line 2325 of file qdeclarativeengine.cpp.

Referenced by main().

2326 {
2328  d->scriptEngine.offlineStoragePath = dir;
2329 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDeclarativeEngine class provides an environment for instantiating QML components.

◆ setOutputWarningsToStandardError()

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.

924 {
926  d->outputWarningsToStdErr = enabled;
927 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDeclarativeEngine class provides an environment for instantiating QML components.
#define enabled

◆ setPluginPathList()

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.

See also
pluginPathList() addPluginPath()

Definition at line 2284 of file qdeclarativeengine.cpp.

2285 {
2287  d->importDatabase.setPluginPathList(paths);
2288 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QDeclarativeEngine class provides an environment for instantiating QML components.

◆ warnings

void QDeclarativeEngine::warnings ( const QList< QDeclarativeError > &  warnings)
signal

This signal is emitted when warnings messages are generated by QML.

Friends and Related Functions

◆ qmlInfo()

QDeclarativeInfo qmlInfo ( const QObject object)
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,

qmlInfo(object) << tr("component property is a write-once property");

prints

QML MyCustomType (unknown location): component property is a write-once property

Definition at line 155 of file qdeclarativeinfo.cpp.

◆ qmlRegisterType()

int qmlRegisterType ( const char *  url,
const char *  uri,
int  versionMajor,
int  versionMinor,
const char *  qmlName 
)
related
Warning
This function is not part of the public interface.

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.

◆ qmlRegisterUncreatableType()

int qmlRegisterUncreatableType ( const char *  url,
const char *  uri,
int  versionMajor,
int  versionMinor,
const char *  qmlName 
)
related
Warning
This function is not part of the public interface.

This overload is backported from Qt5, and allows uncreatable types to be versioned.

Properties

◆ offlineStoragePath

QString QDeclarativeEngine::offlineStoragePath
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.


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