Qt 4.8
Public Functions | Static Public Functions | Public Variables | List of all members
QDeclarativeScriptEngine Class Reference

#include <qdeclarativeengine_p.h>

Inheritance diagram for QDeclarativeScriptEngine:
QScriptEngine QObject QDeclarativeWorkerScriptEnginePrivate::ScriptEngine

Public Functions

virtual QNetworkAccessManagernetworkAccessManager ()
 
 QDeclarativeScriptEngine (QDeclarativeEnginePrivate *priv)
 
QUrl resolvedUrl (QScriptContext *context, const QUrl &url)
 
virtual ~QDeclarativeScriptEngine ()
 
- Public Functions inherited from QScriptEngine
void abortEvaluation (const QScriptValue &result=QScriptValue())
 Aborts any script evaluation currently taking place in this engine. More...
 
QScriptEngineAgentagent () const
 Returns the agent currently installed on this engine, or 0 if no agent is installed. More...
 
QStringList availableExtensions () const
 Returns a list naming the available extensions that can be imported using the importExtension() function. More...
 
bool canEvaluate (const QString &program) const
 Returns true if program can be evaluated; i. More...
 
void clearExceptions ()
 Clears any uncaught exceptions in this engine. More...
 
void collectGarbage ()
 Runs the garbage collector. More...
 
QScriptContextcurrentContext () const
 Returns the current context. More...
 
QScriptValue defaultPrototype (int metaTypeId) const
 Returns the default prototype associated with the given metaTypeId, or an invalid QScriptValue if no default prototype has been set. More...
 
QScriptValue evaluate (const QString &program, const QString &fileName=QString(), int lineNumber=1)
 Evaluates program, using lineNumber as the base line number, and returns the result of the evaluation. More...
 
QScriptValue evaluate (const QScriptProgram &program)
 Evaluates the given program and returns the result of the evaluation. More...
 
template<typename T >
fromScriptValue (const QScriptValue &value)
 Returns the given value converted to the template type T. More...
 
QScriptValue globalObject () const
 Returns this engine's Global Object. More...
 
bool hasUncaughtException () const
 Returns true if the last script evaluation resulted in an uncaught exception; otherwise returns false. More...
 
QStringList importedExtensions () const
 Returns a list naming the extensions that have been imported using the importExtension() function. More...
 
QScriptValue importExtension (const QString &extension)
 Imports the given extension into this QScriptEngine. More...
 
void installTranslatorFunctions (const QScriptValue &object=QScriptValue())
 Installs translator functions on the given object, or on the Global Object if no object is specified. More...
 
bool isEvaluating () const
 Returns true if this engine is currently evaluating a script, otherwise returns false. More...
 
QScriptValue newActivationObject ()
 
QScriptValue newArray (uint length=0)
 Creates a QtScript object of class Array with the given length. More...
 
QScriptValue newDate (qsreal value)
 Creates a QtScript object of class Date with the given value (the number of milliseconds since 01 January 1970, UTC). More...
 
QScriptValue newDate (const QDateTime &value)
 Creates a QtScript object of class Date from the given value. More...
 
QScriptValue newFunction (FunctionSignature signature, int length=0)
 Creates a QScriptValue that wraps a native (C++) function. More...
 
QScriptValue newFunction (FunctionSignature signature, const QScriptValue &prototype, int length=0)
 Creates a constructor function from fun, with the given length. More...
 
QScriptValue newFunction (FunctionWithArgSignature signature, void *arg)
 
QScriptValue newObject ()
 Creates a QtScript object of class Object. More...
 
QScriptValue newObject (QScriptClass *scriptClass, const QScriptValue &data=QScriptValue())
 Creates a QtScript Object of the given class, scriptClass. More...
 
QScriptValue newQMetaObject (const QMetaObject *metaObject, const QScriptValue &ctor=QScriptValue())
 Creates a QtScript object that represents a QObject class, using the the given metaObject and constructor ctor. More...
 
QScriptValue newQObject (QObject *object, ValueOwnership ownership=QtOwnership, const QObjectWrapOptions &options=0)
 Creates a QtScript object that wraps the given QObject object, using the given ownership. More...
 
QScriptValue newQObject (const QScriptValue &scriptObject, QObject *qtObject, ValueOwnership ownership=QtOwnership, const QObjectWrapOptions &options=0)
 Initializes the given scriptObject to hold the given qtObject, and returns the scriptObject. More...
 
QScriptValue newRegExp (const QRegExp &regexp)
 Creates a QtScript object of class RegExp with the given regexp. More...
 
QScriptValue newRegExp (const QString &pattern, const QString &flags)
 Creates a QtScript object of class RegExp with the given pattern and flags. More...
 
QScriptValue newVariant (const QVariant &value)
 Creates a QtScript object holding the given variant value. More...
 
QScriptValue newVariant (const QScriptValue &object, const QVariant &value)
 Initializes the given Qt Script object to hold the given variant value, and returns the object. More...
 
QScriptValue nullValue ()
 Returns a QScriptValue of the primitive type Null. More...
 
QScriptValue objectById (qint64 id) const
 Returns the object with the given id, or an invalid QScriptValue if there is no object with that id. More...
 
void popContext ()
 Pops the current execution context and restores the previous one. More...
 
int processEventsInterval () const
 Returns the interval in milliseconds between calls to QCoreApplication::processEvents() while the interpreter is running. More...
 
QScriptContextpushContext ()
 Enters a new execution context and returns the associated QScriptContext object. More...
 
 QScriptEngine ()
 Constructs a QScriptEngine object. More...
 
 QScriptEngine (QObject *parent)
 Constructs a QScriptEngine object with the given parent. More...
 
void reportAdditionalMemoryCost (int size)
 Reports an additional memory cost of the given size, measured in bytes, to the garbage collector. More...
 
template<class T >
QScriptValue scriptValueFromQMetaObject ()
 Creates a QScriptValue that represents the Qt class T. More...
 
void setAgent (QScriptEngineAgent *agent)
 Installs the given agent on this engine. More...
 
void setDefaultPrototype (int metaTypeId, const QScriptValue &prototype)
 Sets the default prototype of the C++ type identified by the given metaTypeId to prototype. More...
 
void setGlobalObject (const QScriptValue &object)
 Sets this engine's Global Object to be the given object. More...
 
void setProcessEventsInterval (int interval)
 Sets the interval between calls to QCoreApplication::processEvents to interval milliseconds. More...
 
QScriptValue toObject (const QScriptValue &value)
 Converts the given value to an object, if such a conversion is possible; otherwise returns an invalid QScriptValue. More...
 
template<typename T >
QScriptValue toScriptValue (const T &value)
 Creates a QScriptValue with the given value. More...
 
QScriptString toStringHandle (const QString &str)
 Returns a handle that represents the given string, str. More...
 
QScriptValue uncaughtException () const
 Returns the current uncaught exception, or an invalid QScriptValue if there is no uncaught exception. More...
 
QStringList uncaughtExceptionBacktrace () const
 Returns a human-readable backtrace of the last uncaught exception. More...
 
int uncaughtExceptionLineNumber () const
 Returns the line number where the last uncaught exception occurred. More...
 
QScriptValue undefinedValue ()
 Returns a QScriptValue of the primitive type Undefined. More...
 
virtual ~QScriptEngine ()
 Destroys this QScriptEngine. 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 QDeclarativeScriptEngineget (QScriptEngine *e)
 
static QScriptValue resolvedUrl (QScriptContext *ctxt, QScriptEngine *engine)
 
- Static Public Functions inherited from QScriptEngine
static QScriptSyntaxCheckResult checkSyntax (const QString &program)
 Checks the syntax of the given program. 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)
 

Public Variables

QUrl baseUrl
 
QScriptClassnamedNodeMapClass
 
QScriptClassnodeListClass
 
QString offlineStoragePath
 
QDeclarativeEnginePrivatep
 
QScriptClasssqlQueryClass
 

Additional Inherited Members

- Public Types inherited from QScriptEngine
typedef void(* DemarshalFunction) (const QScriptValue &, void *)
 
typedef QScriptValue(* FunctionSignature) (QScriptContext *, QScriptEngine *)
 
typedef QScriptValue(* FunctionWithArgSignature) (QScriptContext *, QScriptEngine *, void *)
 
typedef QScriptValue(* MarshalFunction) (QScriptEngine *, const void *)
 
enum  QObjectWrapOption {
  ExcludeChildObjects = 0x0001, ExcludeSuperClassMethods = 0x0002, ExcludeSuperClassProperties = 0x0004, ExcludeSuperClassContents = 0x0006,
  SkipMethodsInEnumeration = 0x0008, ExcludeDeleteLater = 0x0010, ExcludeSlots = 0x0020, AutoCreateDynamicProperties = 0x0100,
  PreferExistingWrapperObject = 0x0200
}
 These flags specify options when wrapping a QObject pointer with newQObject(). More...
 
enum  ValueOwnership { QtOwnership, ScriptOwnership, AutoOwnership }
 This enum specifies the ownership when wrapping a C++ value, e. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QScriptEngine
void signalHandlerException (const QScriptValue &exception)
 This signal is emitted when a script function connected to a signal causes an exception. 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...
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Functions inherited from QScriptEngine
 QScriptEngine (QScriptEnginePrivate &dd, QObject *parent=0)
 
- 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

Definition at line 113 of file qdeclarativeengine_p.h.

Constructors and Destructors

◆ QDeclarativeScriptEngine()

QDeclarativeScriptEngine::QDeclarativeScriptEngine ( QDeclarativeEnginePrivate priv)

Definition at line 394 of file qdeclarativeengine.cpp.

396 {
397  // Note that all documentation for stuff put on the global object goes in
398  // doc/src/declarative/globalobject.qdoc
399 
400  bool mainthread = priv != 0;
401 
402  QScriptValue qtObject =
404  globalObject().setProperty(QLatin1String("Qt"), qtObject);
405 
406 #ifndef QT_NO_DESKTOPSERVICES
408  + QDir::separator() + QLatin1String("QML")
409  + QDir::separator() + QLatin1String("OfflineStorage");
410 #endif
411 
412 #ifndef QT_NO_XMLSTREAMREADER
414 #endif
415  qt_add_qmlsqldatabase(this);
416  // XXX A Multimedia "Qt.Sound" class also needs to be made available,
417  // XXX but we don't want a dependency in that cirection.
418  // XXX When the above a done some better way, that way should also be
419  // XXX used to add Qt.Sound class.
420 
421  //types
422  if (mainthread)
424  else
426 
434 
435  if (mainthread) {
436  //color helpers
440  }
441 
442 #ifndef QT_NO_DATESTRING
443  //date/time formatting
447 #endif
448 
449  //misc methods
457 
458  if (mainthread) {
459  qtObject.setProperty(QLatin1String("createQmlObject"),
461  qtObject.setProperty(QLatin1String("createComponent"),
463  }
464 
465  //firebug/webkit compat
466  QScriptValue consoleObject = newObject();
469  globalObject().setProperty(QLatin1String("console"), consoleObject);
470 
471  // translation functions need to be installed
472  // before the global script class is constructed (QTBUG-6437)
474 }
static QScriptValue isQtObject(QScriptContext *, QScriptEngine *)
QScriptValue newFunction(FunctionSignature signature, int length=0)
Creates a QScriptValue that wraps a native (C++) function.
static QScriptValue rgba(QScriptContext *, QScriptEngine *)
static QScriptValue hsla(QScriptContext *, QScriptEngine *)
static QString storageLocation(StandardLocation type)
Returns the default system directory where files of type belong, or an empty string if the location c...
static QScriptValue formatTime(QScriptContext *, QScriptEngine *)
static QScriptValue include(QScriptContext *ctxt, QScriptEngine *engine)
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
static QScriptValue createQmlObject(QScriptContext *, QScriptEngine *)
static QScriptValue quit(QScriptContext *, QScriptEngine *)
static const QMetaObject * get()
QScriptValue globalObject() const
Returns this engine&#39;s Global Object.
static QScriptValue formatDate(QScriptContext *, QScriptEngine *)
static QScriptValue size(QScriptContext *, QScriptEngine *)
static QScriptValue btoa(QScriptContext *, QScriptEngine *)
static QScriptValue tint(QScriptContext *, QScriptEngine *)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static QScriptValue worker_include(QScriptContext *ctxt, QScriptEngine *engine)
static QScriptValue lighter(QScriptContext *, QScriptEngine *)
static QScriptValue createComponent(QScriptContext *, QScriptEngine *)
static QChar separator()
Returns the native directory separator: "/" under Unix (including Mac OS X) and "\\" under Windows...
Definition: qdir.cpp:1831
static QScriptValue point(QScriptContext *, QScriptEngine *)
static QScriptValue darker(QScriptContext *, QScriptEngine *)
void qt_add_qmlxmlhttprequest(QScriptEngine *engine)
void installTranslatorFunctions(const QScriptValue &object=QScriptValue())
Installs translator functions on the given object, or on the Global Object if no object is specified...
static QScriptValue consoleLog(QScriptContext *, QScriptEngine *)
QScriptValue newObject()
Creates a QtScript object of class Object.
void qt_add_qmlsqldatabase(QScriptEngine *engine)
static QScriptValue md5(QScriptContext *, QScriptEngine *)
QUrl resolvedUrl(QScriptContext *context, const QUrl &url)
static QScriptValue desktopOpenUrl(QScriptContext *, QScriptEngine *)
void setProperty(const QString &name, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
Sets the value of this QScriptValue&#39;s property with the given name to the given value.
static QScriptValue vector3d(QScriptContext *, QScriptEngine *)
static QScriptValue rect(QScriptContext *, QScriptEngine *)
static QScriptValue fontFamilies(QScriptContext *, QScriptEngine *)
QDeclarativeEnginePrivate * p
QScriptValue newQMetaObject(const QMetaObject *metaObject, const QScriptValue &ctor=QScriptValue())
Creates a QtScript object that represents a QObject class, using the the given metaObject and constru...
static QScriptValue atob(QScriptContext *, QScriptEngine *)
static QScriptValue formatDateTime(QScriptContext *, QScriptEngine *)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ ~QDeclarativeScriptEngine()

QDeclarativeScriptEngine::~QDeclarativeScriptEngine ( )
virtual

Definition at line 476 of file qdeclarativeengine.cpp.

477 {
478  delete sqlQueryClass;
479  delete nodeListClass;
480  delete namedNodeMapClass;
481 }

Functions

◆ get()

static QDeclarativeScriptEngine* QDeclarativeScriptEngine::get ( QScriptEngine e)
inlinestatic

◆ networkAccessManager()

QNetworkAccessManager * QDeclarativeScriptEngine::networkAccessManager ( )
virtual

Reimplemented in QDeclarativeWorkerScriptEnginePrivate::ScriptEngine.

Definition at line 490 of file qdeclarativeengine.cpp.

Referenced by QDeclarativeInclude::QDeclarativeInclude().

491 {
492  return p->getNetworkAccessManager();
493 }
QNetworkAccessManager * getNetworkAccessManager() const
QDeclarativeEnginePrivate * p

◆ resolvedUrl() [1/2]

QUrl QDeclarativeScriptEngine::resolvedUrl ( QScriptContext context,
const QUrl url 
)

Definition at line 382 of file qdeclarativeengine.cpp.

Referenced by QDeclarativeEnginePrivate::createComponent(), QDeclarativeScriptEngine(), qmlxmlhttprequest_open(), and resolvedUrl().

383 {
384  if (p) {
385  QDeclarativeContextData *ctxt = p->getContext(context);
386  if (ctxt)
387  return ctxt->resolvedUrl(url);
388  else
389  return p->getUrl(context).resolved(url);
390  }
391  return baseUrl.resolved(url);
392 }
QUrl resolvedUrl(const QUrl &)
QUrl getUrl(QScriptContext *)
Returns the QUrl associated with the script ctxt for the case that there is no QDeclarativeContext.
QDeclarativeEnginePrivate * p
QUrl resolved(const QUrl &relative) const
Returns the result of the merge of this URL with relative.
Definition: qurl.cpp:5819
QDeclarativeContextData * getContext(QScriptContext *)
Returns the QDeclarativeContext for the executing QScript ctxt.

◆ resolvedUrl() [2/2]

QScriptValue QDeclarativeScriptEngine::resolvedUrl ( QScriptContext ctxt,
QScriptEngine engine 
)
static

Definition at line 483 of file qdeclarativeengine.cpp.

484 {
485  QString arg = ctxt->argument(0).toString();
486  QUrl r = QDeclarativeScriptEngine::get(engine)->resolvedUrl(ctxt,QUrl(arg));
487  return QScriptValue(r.toString());
488 }
QString toString(FormattingOptions options=None) const
Returns the human-displayable string representation of the URL.
Definition: qurl.cpp:5896
QString toString() const
Returns the string value of this QScriptValue, as defined in ECMA-262 section 9.8, "ToString".
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QDeclarativeScriptEngine * get(QScriptEngine *e)
QUrl resolvedUrl(QScriptContext *context, const QUrl &url)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
QScriptValue argument(int index) const
Returns the function argument at the given index.

Properties

◆ baseUrl

QUrl QDeclarativeScriptEngine::baseUrl

◆ namedNodeMapClass

QScriptClass* QDeclarativeScriptEngine::namedNodeMapClass

Definition at line 131 of file qdeclarativeengine_p.h.

Referenced by NamedNodeMap::create(), and ~QDeclarativeScriptEngine().

◆ nodeListClass

QScriptClass* QDeclarativeScriptEngine::nodeListClass

Definition at line 132 of file qdeclarativeengine_p.h.

Referenced by NodeList::create(), and ~QDeclarativeScriptEngine().

◆ offlineStoragePath

QString QDeclarativeScriptEngine::offlineStoragePath

◆ p

QDeclarativeEnginePrivate* QDeclarativeScriptEngine::p

◆ sqlQueryClass

QScriptClass* QDeclarativeScriptEngine::sqlQueryClass

Definition at line 127 of file qdeclarativeengine_p.h.

Referenced by qmlsqldatabase_executeSql(), and ~QDeclarativeScriptEngine().


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