Qyoto  4.0.5
Qyoto is a C# language binding for Qt
 All Classes Namespaces Functions Variables Typedefs Enumerations Properties
QtScript.QScriptEngine Class Reference

The QScriptEngine class provides an environment for evaluating Qt Script code. More...

Inheritance diagram for QtScript.QScriptEngine:
Collaboration diagram for QtScript.QScriptEngine:

Public Types

enum  QObjectWrapOption {
  AutoCreateDynamicProperties = 256, ExcludeChildObjects = 1, ExcludeDeleteLater = 16, ExcludeSlots = 32,
  ExcludeSuperClassContents = 6, ExcludeSuperClassMethods = 2, ExcludeSuperClassProperties = 4, PreferExistingWrapperObject = 512,
  SkipMethodsInEnumeration = 8
}
  More...
 
enum  ValueOwnership { AutoOwnership = 2, QtOwnership = 0, ScriptOwnership = 1 }
  More...
 

Public Member Functions

 QScriptEngine ()
 
 
 QScriptEngine (QObject parent)
 
 
override void CreateProxy ()
 
new void AbortEvaluation ()
 
 
new void AbortEvaluation (QScriptValue result)
 
 
new
System.Collections.Generic.List
< string > 
AvailableExtensions ()
 
 
new bool CanEvaluate (string program)
 
 
new void ClearExceptions ()
 
 
new void CollectGarbage ()
 
 
new QScriptContext CurrentContext ()
 
 
new QScriptValue DefaultPrototype (int metaTypeId)
 
 
new QScriptValue Evaluate (string program, string fileName="", int lineNumber=1)
 
 
new bool HasUncaughtException ()
 
 
new QScriptValue ImportExtension (string extension)
 
 
new
System.Collections.Generic.List
< string > 
ImportedExtensions ()
 
 
new void InstallTranslatorFunctions ()
 
 
new void InstallTranslatorFunctions (QScriptValue @object)
 
 
new bool IsEvaluating ()
 
 
new QScriptValue NewActivationObject ()
 
new QScriptValue NewArray (uint length=0)
 
 
new QScriptValue NewDate (QDateTime value)
 
 
new QScriptValue NewDate (double value)
 
 
new QScriptValue NewFunction (Global.FuncQScriptValueQScriptContextQScriptEngine signature, QScriptValue prototype, int length=0)
 
 
new QScriptValue NewFunction (Global.FuncQScriptValueQScriptContextQScriptEngine signature, int length=0)
 
 
new QScriptValue NewObject ()
 
 
new QScriptValue NewObject (QScriptClass scriptClass)
 
 
new QScriptValue NewObject (QScriptClass scriptClass, QScriptValue data)
 
 
new QScriptValue NewQMetaObject (QMetaObject metaObject)
 
 
new QScriptValue NewQMetaObject (QMetaObject metaObject, QScriptValue ctor)
 
 
new QScriptValue NewQObject (QScriptValue scriptObject, QObject qtObject, QScriptEngine.ValueOwnership ownership=QScriptEngine.ValueOwnership.QtOwnership, QScriptEngine.QObjectWrapOption options=0)
 
 
new QScriptValue NewQObject (QObject @object, QScriptEngine.ValueOwnership ownership=QScriptEngine.ValueOwnership.QtOwnership, QScriptEngine.QObjectWrapOption options=0)
 
 
new QScriptValue NewRegExp (QRegExp regexp)
 
 
new QScriptValue NewRegExp (string pattern, string flags)
 
 
new QScriptValue NewVariant (object value)
 
 
new QScriptValue NewVariant (QScriptValue @object, object value)
 
 
new QScriptValue NullValue ()
 
 
new QScriptValue ObjectById (long id)
 
new void PopContext ()
 
 
new QScriptContext PushContext ()
 
 
new void ReportAdditionalMemoryCost (int size)
 
 
new void SetDefaultPrototype (int metaTypeId, QScriptValue prototype)
 
 
new QScriptValue ToObject (QScriptValue value)
 
 
new QScriptString ToStringHandle (string str)
 
 
new QScriptValue UncaughtException ()
 
 
new
System.Collections.Generic.List
< string > 
UncaughtExceptionBacktrace ()
 
 
new int UncaughtExceptionLineNumber ()
 
 
new QScriptValue UndefinedValue ()
 
 
new void Dispose ()
 
- Public Member Functions inherited from QtCore.QObject
 QObject (QObject parent=null)
 
 
new bool BlockSignals (bool b)
 
 
new
System.Collections.Generic.List
< QObject
Children ()
 
 
new bool Connect (QObject sender, string signal, string member, Qt.ConnectionType type=Qt.ConnectionType.AutoConnection)
 
 
new void DeleteLater ()
 
 
new bool Disconnect (QObject receiver, string member=null)
 
 
new bool Disconnect (string signal=null, QObject receiver=null, string member=null)
 
 
new void DumpObjectInfo ()
 
 
new void DumpObjectTree ()
 
 
new
System.Collections.Generic.List
< QByteArray
DynamicPropertyNames ()
 
 
virtual bool OnEvent (QEvent arg1)
 
 
virtual bool EventFilter (QObject arg1, QEvent arg2)
 
 
new bool Inherits (string classname)
 
 
new void InstallEventFilter (QObject arg1)
 
 
new bool IsWidgetType ()
 
 
new void KillTimer (int id)
 
 
new object Property (string name)
 
 
new void RemoveEventFilter (QObject arg1)
 
 
new bool SetProperty (string name, object value)
 
 
new void SetUserData (uint id, QObjectUserData data)
 
new bool SignalsBlocked ()
 
 
new int StartTimer (int interval)
 
 
new QObjectUserData UserData (uint id)
 
new void Dispose ()
 
- Public Member Functions inherited from QtCore.Qt
delegate QTextStream FuncQTextStreamQTextStream (QTextStream qTextStream)
 
delegate string FuncStringQByteArray (QByteArray qByteArray)
 
delegate QByteArray FuncQByteArrayString (string @string)
 
delegate void ActionQtMsgTypeString (QtMsgType qtMsgType, string @string)
 
delegate QObject FuncQObject ()
 

Static Public Member Functions

static QScriptSyntaxCheckResult CheckSyntax (string program)
 
 
static string Tr (string s, string c=null)
 
static string Tr (string s, string c, int n)
 
static string TrUtf8 (string s, string c=null)
 
static string TrUtf8 (string s, string c, int n)
 
- Static Public Member Functions inherited from QtCore.QObject
static bool Connect (QObject sender, QMetaMethod signal, QObject receiver, QMetaMethod method, Qt.ConnectionType type=Qt.ConnectionType.AutoConnection)
 
 
static bool Connect (QObject sender, string signal, QObject receiver, string member, Qt.ConnectionType arg5=Qt.ConnectionType.AutoConnection)
 
 
static bool Disconnect (QObject sender, QMetaMethod signal, QObject receiver, QMetaMethod member)
 
 
static bool Disconnect (QObject sender, string signal, QObject receiver, string member)
 
 
static uint RegisterUserData ()
 
static string Tr (string s, string c=null)
 
 
static string Tr (string s, string c, int n)
 
 
static string TrUtf8 (string s, string c=null)
 
 
static string TrUtf8 (string s, string c, int n)
 
 
- Static Public Member Functions inherited from QtCore.Qt
static QDataStream Write (QDataStream s, object p)
 
static QDataStream Write (QDataStream arg1, QSizeF arg2)
 
static QTextStream Write (QTextStream s, Qt.FuncQTextStreamQTextStream f)
 
static QDataStream Write (QDataStream arg1, QPoint arg2)
 
static QDataStream Write (QDataStream arg1, QLineF arg2)
 
static QDataStream Write (QDataStream arg1, QPointF arg2)
 
static QDataStream Write (QDataStream arg1, QChar arg2)
 
static QDataStream Write (QDataStream arg1, QByteArray arg2)
 
static QDataStream Write (QDataStream arg1, QEasingCurve arg2)
 
static QDataStream Write (QDataStream arg1, QRectF arg2)
 
static QDataStream Write (QDataStream arg1, QDateTime arg2)
 
static QDataStream Write (QDataStream arg1, QUrl arg2)
 
static QDataStream Write (QDataStream arg1, QTime arg2)
 
static QDataStream Write (QDataStream arg1, QLocale arg2)
 
static QDataStream Write (QDataStream arg1, QBitArray arg2)
 
static QDataStream Write (QDataStream arg1, QUuid arg2)
 
static QDataStream Write (QDataStream arg1, QLine arg2)
 
static QDataStream Write (QDataStream arg1, QDate arg2)
 
static QDataStream Write (QDataStream @out, QRegExp regExp)
 
static QDataStream Write (QDataStream arg1, QRect arg2)
 
static QDataStream Write (QDataStream arg1, QSize arg2)
 
static QDataStream Write (QDataStream s, QVariant.Type p)
 
static QDataStream Write (QDataStream arg1, string arg2)
 
static QDataStream Write (QDataStream @out, System.Collections.Generic.List< string > list)
 
static QDataStream Read (QDataStream arg1, QChar arg2)
 
static QDataStream Read (QDataStream arg1, QLocale arg2)
 
static QDataStream Read (QDataStream arg1, QRect arg2)
 
static QDataStream Read (QDataStream arg1, QEasingCurve arg2)
 
static QDataStream Read (QDataStream arg1, QDate arg2)
 
static QDataStream Read (QDataStream arg1, QUrl arg2)
 
static QDataStream Read (QDataStream arg1, QUuid arg2)
 
static QTextStream Read (QTextStream s, Qt.FuncQTextStreamQTextStream f)
 
static QDataStream Read (QDataStream arg1, QLineF arg2)
 
static QDataStream Read (QDataStream arg1, QRectF arg2)
 
static QDataStream Read (QDataStream arg1, QPointF arg2)
 
static QDataStream Read (QDataStream arg1, QLine arg2)
 
static QDataStream Read (QDataStream arg1, QBitArray arg2)
 
static QDataStream Read (QDataStream arg1, QSize arg2)
 
static QDataStream Read (QDataStream arg1, QDateTime arg2)
 
static QDataStream Read (QDataStream arg1, QTime arg2)
 
static QDataStream Read (QDataStream arg1, QPoint arg2)
 
static QDataStream Read (QDataStream @in, QRegExp regExp)
 
static QDataStream Read (QDataStream s, object p)
 
static QDataStream Read (QDataStream arg1, QByteArray arg2)
 
static QDataStream Read (QDataStream arg1, QSizeF arg2)
 
static QDataStream Read (QDataStream arg1, string arg2)
 
static QDataStream Read (QDataStream s, QVariant.Type p)
 
static QDataStream Read (QDataStream @in, System.Collections.Generic.List< string > list)
 
static double qAcos (double v)
 
static void qAddPostRoutine (System.Action arg1)
 
static string qAppName ()
 
static double qAsin (double v)
 
static double qAtan (double v)
 
static double qAtan2 (double x, double y)
 
static void qBadAlloc ()
 
static int qCeil (double v)
 
static ushort qChecksum (string s, uint len)
 
static QByteArray qCompress (QByteArray data)
 
static QByteArray qCompress (QByteArray data, int compressionLevel=-1)
 
static QByteArray qCompress (Pointer< byte > data, int nbytes)
 
static QByteArray qCompress (Pointer< byte > data, int nbytes, int compressionLevel=-1)
 
static double qCos (double v)
 
static double qExp (double v)
 
static double qFabs (double v)
 
static double qFastCos (double x)
 
static double qFastSin (double x)
 
static string qFlagLocation (string method)
 
static int qFloor (double v)
 
static bool qFuzzyCompare (double p1, double p2)
 
static bool qFuzzyCompare (float p1, float p2)
 
static bool qFuzzyIsNull (double d)
 
static bool qFuzzyIsNull (float f)
 
static uint qHash (QBitArray key)
 
static uint qHash (QChar key)
 
static uint qHash (QStringRef key)
 
static uint qHash (QUrl url)
 
static uint qHash (QPersistentModelIndex index)
 
static uint qHash (QByteArray key)
 
static uint qHash (QModelIndex index)
 
static uint qHash (uint key)
 
static uint qHash (sbyte key)
 
static uint qHash (byte key)
 
static uint qHash (short key)
 
static uint qHash (NativeLong key)
 
static uint qHash (ushort key)
 
static uint qHash (long key)
 
static uint qHash (ulong key)
 
static uint qHash (int key)
 
static uint qHash (string key)
 
static uint qHash (NativeULong key)
 
static double qInf ()
 
static Qt.ActionQtMsgTypeString qInstallMsgHandler (Qt.ActionQtMsgTypeString arg1)
 
static int qIntCast (float f)
 
static int qIntCast (double f)
 
static bool qIsFinite (double d)
 
static bool qIsFinite (float f)
 
static bool qIsInf (float f)
 
static bool qIsInf (double d)
 
static bool qIsNaN (float f)
 
static bool qIsNaN (double d)
 
static bool qIsNull (float f)
 
static bool qIsNull (double d)
 
static double qLn (double v)
 
static double qPow (double x, double y)
 
static double qQNaN ()
 
static void qRegisterStaticPluginInstanceFunction (Qt.FuncQObject function)
 
static void qRemovePostRoutine (System.Action arg1)
 
static int qRound (double d)
 
static long qRound64 (double d)
 
static double qSNaN ()
 
static bool qSharedBuild ()
 
static double qSin (double v)
 
static double qSqrt (double v)
 
static bool qStringComparisonHelper (QStringRef s1, string s2)
 
static double qTan (double v)
 
static QByteArray qUncompress (QByteArray data)
 
static QByteArray qUncompress (Pointer< byte > data, int nbytes)
 
static string qVersion ()
 
static void Qbswap_helper (Pointer< byte > src, Pointer< byte > dest, int size)
 
static QByteArray Qgetenv (string varName)
 
static bool Qputenv (string varName, QByteArray value)
 
static int Qrand ()
 
static void Qsrand (uint seed)
 
static int Qstrcmp (QByteArray str1, QByteArray str2)
 
static int Qstrcmp (QByteArray str1, string str2)
 
static int Qstrcmp (string str1, QByteArray str2)
 
static int Qstrcmp (string str1, string str2)
 
static Pointer< sbyte > Qstrcpy (Pointer< sbyte > dst, string src)
 
static Pointer< sbyte > Qstrdup (string arg1)
 
static int Qstricmp (string arg1, string arg2)
 
static uint Qstrlen (string str)
 
static int Qstrncmp (string str1, string str2, uint len)
 
static Pointer< sbyte > Qstrncpy (Pointer< sbyte > dst, string src, uint len)
 
static int Qstrnicmp (string arg1, string arg2, uint len)
 
static uint Qstrnlen (string str, uint maxlen)
 
static string QtTrId (string id, int n=-1)
 

Protected Member Functions

 QScriptEngine (System.Type dummy)
 
new void OnSignalHandlerException (QScriptValue exception)
 
 
- Protected Member Functions inherited from QtCore.QObject
 QObject (System.Type dummy)
 
virtual void OnChildEvent (QChildEvent arg1)
 
 
virtual void ConnectNotify (string signal)
 
 
virtual void OnCustomEvent (QEvent arg1)
 
 
new void OnDestroyed (QObject arg1=null)
 
 
virtual void DisconnectNotify (string signal)
 
 
new int Receivers (string signal)
 
 
new QObject Sender ()
 
 
new int SenderSignalIndex ()
 
 
virtual void OnTimerEvent (QTimerEvent arg1)
 
 

Properties

Slot< QScriptValueSignalHandlerException
 
 
new QScriptEngineAgent Agent [get, set]
 
 
new QScriptValue GlobalObject [get, set]
 
 
new int ProcessEventsInterval [get, set]
 
 
static new QMetaObject StaticMetaObject [get]
 
new IQScriptEngineSignals Emit [get]
 
- Properties inherited from QtCore.QObject
virtual EventHandler
< QEventArgs< QChildEvent > > 
ChildEvent
 
 
virtual EventHandler
< QEventArgs< QEvent > > 
CustomEvent
 
 
virtual EventHandler
< QEventArgs< QEvent > > 
Event
 
 
virtual EventHandler
< QEventArgs< QTimerEvent > > 
TimerEvent
 
 
Slot< QObjectDestroyedQObject
 
Slot Destroyed
 
 
new QObject Parent [get, set]
 
 
virtual System.IntPtr SmokeObject [get, set]
 
new string ObjectName [get, set]
 
 
static new QMetaObject StaticMetaObject [get]
 
 
static new QMetaObject StaticQtMetaObject [get]
 
new IQObjectSignals Emit [get]
 

Additional Inherited Members

- Protected Attributes inherited from QtCore.QObject
object Q_EMIT = null
 
SmokeInvocation interceptor
 
readonly List< QEventHandler > eventFilters = new List<QEventHandler>()
 

Detailed Description

The QScriptEngine class provides an environment for evaluating Qt Script code.

See the QtScript documentation for information about the Qt Script language, and how to get started with scripting your C++ application.

Evaluating Scripts

Use evaluate() to evaluate script code; this is the C++ equivalent of the built-in script function eval().

QScriptEngine myEngine;

QScriptValue three = myEngine.evaluate("1 + 2");

evaluate() returns a QScriptValue that holds the result of the evaluation. The QScriptValue class provides functions for converting the result to various C++ types (e.g. QScriptValue::toString() and QScriptValue::toNumber()).

The following code snippet shows how a script function can be defined and then invoked from C++ using QScriptValue::call():

QScriptValue fun = myEngine.evaluate("(function(a, b) { return a + b; })");

QScriptValueList args;

args << 1 << 2;

QScriptValue threeAgain = fun.call(QScriptValue(), args);

As can be seen from the above snippets, a script is provided to the engine in the form of a string. One common way of loading scripts is by reading the contents of a file and passing it to evaluate():

QString fileName = "helloworld.qs";

QFile scriptFile(fileName);

if (!scriptFile.open(QIODevice::ReadOnly))

// handle error

QTextStream stream(&scriptFile);

QString contents = stream.readAll();

scriptFile.close();

myEngine.evaluate(contents, fileName);

Here we pass the name of the file as the second argument to evaluate(). This does not affect evaluation in any way; the second argument is a general-purpose string that is used to identify the script for debugging purposes (for example, our filename will now show up in any uncaughtExceptionBacktrace() involving the script).

Engine Configuration

The globalObject() function returns the Global Object associated with the script engine. Properties of the Global Object are accessible from any script code (i.e. they are global variables). Typically, before evaluating "user" scripts, you will want to configure a script engine by adding one or more properties to the Global Object:

myEngine.globalObject().setProperty("myNumber", 123);

...

QScriptValue myNumberPlusOne = myEngine.evaluate("myNumber + 1");

Adding custom properties to the scripting environment is one of the standard means of providing a scripting API that is specific to your application. Usually these custom properties are objects created by the newQObject() or newObject() functions, or constructor functions created by newFunction().

Script Exceptions

evaluate() can throw a script exception (e.g. due to a syntax error); in that case, the return value is the value that was thrown (typically an Error object). You can check whether the evaluation caused an exception by calling hasUncaughtException(). In that case, you can call toString() on the error object to obtain an error message. The current uncaught exception is also available through uncaughtException(). Calling clearExceptions() will cause any uncaught exceptions to be cleared.

QScriptValue result = myEngine.evaluate(...);

if (myEngine.hasUncaughtException()) {

int line = myEngine.uncaughtExceptionLineNumber();

qDebug() << "uncaught exception at line" << line << ":" << result.toString();

}

The checkSyntax() function can be used to determine whether code can be usefully passed to evaluate().

Script Object Creation

Use newObject() to create a standard Qt Script object; this is the C++ equivalent of the script statement new Object(). You can use the object-specific functionality in QScriptValue to manipulate the script object (e.g. QScriptValue::setProperty()). Similarly, use newArray() to create a Qt Script array object. Use newDate() to create a Date object, and newRegExp() to create a RegExp object.

QObject Integration

Use newQObject() to wrap a QObject (or subclass) pointer. newQObject() returns a proxy script object; properties, children, and signals and slots of the QObject are available as properties of the proxy object. No binding code is needed because it is done dynamically using the Qt meta object system.

QPushButton button;

QScriptValue scriptButton = myEngine.newQObject(&button);

myEngine.globalObject().setProperty("button", scriptButton);

myEngine.evaluate("button.checkable = true");

qDebug() << scriptButton.property("checkable").toBoolean();

scriptButton.property("show").call(); // call the show() slot

Use qScriptConnect() to connect a C++ signal to a script function; this is the Qt Script equivalent of QObject::connect(). When a script function is invoked in response to a C++ signal, it can cause a script exception; you can connect to the signalHandlerException() signal to catch such an exception.

Use newQMetaObject() to wrap a QMetaObject; this gives you a "script representation" of a QObject-based class. newQMetaObject() returns a proxy script object; enum values of the class are available as properties of the proxy object. You can also specify a function that will be used to construct objects of the class (e.g. when the constructor is invoked from a script). For classes that have a "standard" Qt constructor, Qt Script can provide a default script constructor for you; see scriptValueFromQMetaObject().

For more information about QObject integration, see Making Applications Scriptable

Support for Custom C++ Types

Use newVariant() to wrap a QVariant. This can be used to store values of custom (non-QObject) C++ types that have been registered with the Qt meta-type system. To make such types scriptable, you typically associate a prototype (delegate) object with the C++ type by calling setDefaultPrototype(); the prototype object defines the scripting API for the C++ type. Unlike the QObject integration, there is no automatic binding possible here; i.e. you have to create the scripting API yourself, for example by using the QScriptable class.

Use fromScriptValue() to cast from a QScriptValue to another type, and toScriptValue() to create a QScriptValue from another value. You can specify how the conversion of C++ types is to be performed with qScriptRegisterMetaType() and qScriptRegisterSequenceMetaType(). By default, Qt Script will use QVariant to store values of custom types.

Importing Extensions

Use importExtension() to import plugin-based extensions into the engine. Call availableExtensions() to obtain a list naming all the available extensions, and importedExtensions() to obtain a list naming only those extensions that have been imported.

Call pushContext() to open up a new variable scope, and popContext() to close the current scope. This is useful if you are implementing an extension that evaluates script code containing temporary variable definitions (e.g. var foo = 123;) that are safe to discard when evaluation has completed.

Native Functions

Use newFunction() to wrap native (C++) functions, including constructors for your own custom types, so that these can be invoked from script code. Such functions must have the signature QScriptEngine::FunctionSignature. You may then pass the function as argument to newFunction(). Here is an example of a function that returns the sum of its first two arguments:

QScriptValue myAdd(QScriptContext *context, QScriptEngine *engine)

{

QScriptValue a = context->argument(0);

QScriptValue b = context->argument(1);

return a.toNumber() + b.toNumber();

}

To expose this function to script code, you can set it as a property of the Global Object:

QScriptValue fun = myEngine.newFunction(myAdd);

myEngine.globalObject().setProperty("myAdd", fun);

Once this is done, script code can call your function in the exact same manner as a "normal" script function:

QScriptValue result = myEngine.evaluate("myAdd(myNumber, 1)");

Long-running Scripts

If you need to evaluate possibly long-running scripts from the main (GUI) thread, you should first call setProcessEventsInterval() to make sure that the GUI stays responsive. You can abort a currently running script by calling abortEvaluation(). You can determine whether an engine is currently running a script by calling isEvaluating().

Garbage Collection

Qt Script objects may be garbage collected when they are no longer referenced. There is no guarantee as to when automatic garbage collection will take place.

The collectGarbage() function can be called to explicitly request garbage collection.

The reportAdditionalMemoryCost() function can be called to indicate that a Qt Script object occupies memory that isn't managed by the scripting environment. Reporting the additional cost makes it more likely that the garbage collector will be triggered. This can be useful, for example, when many custom, native Qt Script objects are allocated.

Core Debugging/Tracing Facilities

Since Qt 4.4, you can be notified of events pertaining to script execution (e.g. script function calls and statement execution) through the QScriptEngineAgent interface; see the setAgent() function. This can be used to implement debugging and profiling of a QScriptEngine.

See also QScriptValue, QScriptContext, and QScriptEngineAgent.

Member Enumeration Documentation

These flags specify options when wrapping a QObject pointer with newQObject().

Enumerator:
AutoCreateDynamicProperties 

Properties that don't already exist in the QObject will be created as dynamic properties of that object, rather than as properties of the script object.

ExcludeChildObjects 

The script object will not expose child objects as properties.

ExcludeDeleteLater 

The script object will not expose the QObject::deleteLater() slot.

ExcludeSlots 

The script object will not expose the QObject's slots.

ExcludeSuperClassContents 

Shorthand form for ExcludeSuperClassMethods | ExcludeSuperClassProperties

ExcludeSuperClassMethods 

The script object will not expose signals and slots inherited from the superclass.

ExcludeSuperClassProperties 

The script object will not expose properties inherited from the superclass.

PreferExistingWrapperObject 

If a wrapper object with the requested configuration already exists, return that object.

SkipMethodsInEnumeration 

Don't include methods (signals and slots) when enumerating the object's properties.

This enum specifies the ownership when wrapping a C++ value, e.g. by using newQObject().

Enumerator:
AutoOwnership 

If the associated object has a parent, the Qt ownership rules apply (QtOwnership); otherwise, the object is owned by the script environment (ScriptOwnership).

QtOwnership 

The standard Qt ownership rules apply, i.e. the associated object will never be explicitly deleted by the script engine. This is the default. (QObject ownership is explained in Object Trees & Ownership.)

ScriptOwnership 

The value is owned by the script environment. The associated data will be deleted when appropriate (i.e. after the garbage collector has discovered that there are no more live references to the value).

Constructor & Destructor Documentation

QtScript.QScriptEngine.QScriptEngine ( System.Type  dummy)
protected
QtScript.QScriptEngine.QScriptEngine ( )

Constructs a QScriptEngine object.

The globalObject() is initialized to have properties as described in ECMA-262, Section 15.1.

QtScript.QScriptEngine.QScriptEngine ( QObject  parent)

Constructs a QScriptEngine object with the given parent.

The globalObject() is initialized to have properties as described in ECMA-262, Section 15.1.

Member Function Documentation

new void QtScript.QScriptEngine.AbortEvaluation ( )

Aborts any script evaluation currently taking place in this engine. The given result is passed back as the result of the evaluation (i.e. it is returned from the call to evaluate() being aborted).

If the engine isn't evaluating a script (i.e. isEvaluating() returns false), this function does nothing.

Call this function if you need to abort a running script for some reason, e.g. when you have detected that the script has been running for several seconds without completing.

This function was introduced in Qt 4.4.

See also evaluate(), isEvaluating(), and setProcessEventsInterval().

new void QtScript.QScriptEngine.AbortEvaluation ( QScriptValue  result)

Aborts any script evaluation currently taking place in this engine. The given result is passed back as the result of the evaluation (i.e. it is returned from the call to evaluate() being aborted).

If the engine isn't evaluating a script (i.e. isEvaluating() returns false), this function does nothing.

Call this function if you need to abort a running script for some reason, e.g. when you have detected that the script has been running for several seconds without completing.

This function was introduced in Qt 4.4.

See also evaluate(), isEvaluating(), and setProcessEventsInterval().

new System.Collections.Generic.List<string> QtScript.QScriptEngine.AvailableExtensions ( )

Returns a list naming the available extensions that can be imported using the importExtension() function. This list includes extensions that have been imported.

This function was introduced in Qt 4.4.

See also importExtension() and importedExtensions().

new bool QtScript.QScriptEngine.CanEvaluate ( string  program)

Returns true if program can be evaluated; i.e. the code is sufficient to determine whether it appears to be a syntactically correct program, or contains a syntax error.

This function returns false if program is incomplete; i.e. the input is syntactically correct up to the point where the input is terminated.

Note that this function only does a static check of program; e.g. it does not check whether references to variables are valid, and so on.

A typical usage of canEvaluate() is to implement an interactive interpreter for QtScript. The user is repeatedly queried for individual lines of code; the lines are concatened internally, and only when canEvaluate() returns true for the resulting program is it passed to evaluate().

The following are some examples to illustrate the behavior of canEvaluate(). (Note that all example inputs are assumed to have an explicit newline as their last character, since otherwise the QtScript parser would automatically insert a semi-colon character at the end of the input, and this could cause canEvaluate() to produce different results.)

Given the input

if (hello && world)

print("hello world");

canEvaluate() will return true, since the program appears to be complete.

Given the input

if (hello &&

canEvaluate() will return false, since the if-statement is not complete, but is syntactically correct so far.

Given the input

0 = 0

canEvaluate() will return true, but evaluate() will throw a SyntaxError given the same input.

Given the input

./test.js

canEvaluate() will return true, even though the code is clearly not syntactically valid QtScript code. evaluate() will throw a SyntaxError when this code is evaluated.

Given the input

foo["bar"]

canEvaluate() will return true, but evaluate() will throw a ReferenceError if foo is not defined in the script environment.

See also evaluate() and checkSyntax().

Related Non-Members

QScriptValue qScriptValueFromValue ( QScriptEngine * engine, const T & value )

Creates a QScriptValue using the given engine with the given value of template type T.

This function is equivalent to QScriptEngine::toScriptValue().

Note: This function was provided as a workaround for MSVC 6 which did not support member template functions. It is advised to use the other form in new code.

This function was introduced in Qt 4.3.

See also QScriptEngine::toScriptValue() and qscriptvalue_cast().

static QScriptSyntaxCheckResult QtScript.QScriptEngine.CheckSyntax ( string  program)
static

Checks the syntax of the given program. Returns a QScriptSyntaxCheckResult object that contains the result of the check.

This function was introduced in Qt 4.5.

new void QtScript.QScriptEngine.ClearExceptions ( )

Clears any uncaught exceptions in this engine.

This function was introduced in Qt 4.4.

See also hasUncaughtException().

new void QtScript.QScriptEngine.CollectGarbage ( )

Runs the garbage collector.

The garbage collector will attempt to reclaim memory by locating and disposing of objects that are no longer reachable in the script environment.

Normally you don't need to call this function; the garbage collector will automatically be invoked when the QScriptEngine decides that it's wise to do so (i.e. when a certain number of new objects have been created). However, you can call this function to explicitly request that garbage collection should be performed as soon as possible.

See also reportAdditionalMemoryCost().

override void QtScript.QScriptEngine.CreateProxy ( )
virtual

Reimplemented from QtCore.QObject.

new QScriptContext QtScript.QScriptEngine.CurrentContext ( )

Returns the current context.

The current context is typically accessed to retrieve the arguments and `this' object in native functions; for convenience, it is available as the first argument in QScriptEngine::FunctionSignature.

new QScriptValue QtScript.QScriptEngine.DefaultPrototype ( int  metaTypeId)

Returns the default prototype associated with the given metaTypeId, or an invalid QScriptValue if no default prototype has been set.

See also setDefaultPrototype().

new void QtScript.QScriptEngine.Dispose ( )
new QScriptValue QtScript.QScriptEngine.Evaluate ( string  program,
string  fileName = "",
int  lineNumber = 1 
)

Evaluates program, using lineNumber as the base line number, and returns the result of the evaluation.

The script code will be evaluated in the current context.

The evaluation of program can cause an exception in the engine; in this case the return value will be the exception that was thrown (typically an Error object). You can call hasUncaughtException() to determine if an exception occurred in the last call to evaluate().

lineNumber is used to specify a starting line number for program; line number information reported by the engine that pertain to this evaluation (e.g. uncaughtExceptionLineNumber()) will be based on this argument. For example, if program consists of two lines of code, and the statement on the second line causes a script exception, uncaughtExceptionLineNumber() would return the given lineNumber plus one. When no starting line number is specified, line numbers will be 1-based.

fileName is used for error reporting. For example in error objects the file name is accessible through the "fileName" property if it's provided with this function.

See also canEvaluate(), hasUncaughtException(), isEvaluating(), and abortEvaluation().

new bool QtScript.QScriptEngine.HasUncaughtException ( )

Returns true if the last script evaluation resulted in an uncaught exception; otherwise returns false.

The exception state is cleared when evaluate() is called.

See also uncaughtException() and uncaughtExceptionLineNumber().

new System.Collections.Generic.List<string> QtScript.QScriptEngine.ImportedExtensions ( )

Returns a list naming the extensions that have been imported using the importExtension() function.

This function was introduced in Qt 4.4.

See also availableExtensions().

new QScriptValue QtScript.QScriptEngine.ImportExtension ( string  extension)

Imports the given extension into this QScriptEngine. Returns undefinedValue() if the extension was successfully imported. You can call hasUncaughtException() to check if an error occurred; in that case, the return value is the value that was thrown by the exception (usually an Error object).

QScriptEngine ensures that a particular extension is only imported once; subsequent calls to importExtension() with the same extension name will do nothing and return undefinedValue().

See also availableExtensions(), QScriptExtensionPlugin, and Creating QtScript Extensions.

new void QtScript.QScriptEngine.InstallTranslatorFunctions ( )

Installs translator functions on the given object, or on the Global Object if no object is specified.

The relation between Qt Script translator functions and C++ translator functions is described in the following table:

Script FunctionCorresponding C++ Function

qsTr() QObject::tr()

QT_TR_NOOP() QT_TR_NOOP()

qsTranslate() QCoreApplication::translate()

QT_TRANSLATE_NOOP() QT_TRANSLATE_NOOP()

qsTrId() (since 4.7) qtTrId()

QT_TRID_NOOP() (since 4.7) QT_TRID_NOOP()

This function was introduced in Qt 4.5.

See also Internationalization with Qt.

new void QtScript.QScriptEngine.InstallTranslatorFunctions ( QScriptValue object)

Installs translator functions on the given object, or on the Global Object if no object is specified.

The relation between Qt Script translator functions and C++ translator functions is described in the following table:

Script FunctionCorresponding C++ Function

qsTr() QObject::tr()

QT_TR_NOOP() QT_TR_NOOP()

qsTranslate() QCoreApplication::translate()

QT_TRANSLATE_NOOP() QT_TRANSLATE_NOOP()

qsTrId() (since 4.7) qtTrId()

QT_TRID_NOOP() (since 4.7) QT_TRID_NOOP()

This function was introduced in Qt 4.5.

See also Internationalization with Qt.

new bool QtScript.QScriptEngine.IsEvaluating ( )

Returns true if this engine is currently evaluating a script, otherwise returns false.

This function was introduced in Qt 4.4.

See also evaluate() and abortEvaluation().

new QScriptValue QtScript.QScriptEngine.NewActivationObject ( )
new QScriptValue QtScript.QScriptEngine.NewArray ( uint  length = 0)

Creates a QtScript object of class Array with the given length.

See also newObject().

new QScriptValue QtScript.QScriptEngine.NewDate ( QDateTime  value)

Creates a QtScript object of class Date from the given value.

See also QScriptValue::toDateTime().

new QScriptValue QtScript.QScriptEngine.NewDate ( double  value)

Creates a QtScript object of class Date with the given value (the number of milliseconds since 01 January 1970, UTC).

new QScriptValue QtScript.QScriptEngine.NewFunction ( Global.FuncQScriptValueQScriptContextQScriptEngine  signature,
QScriptValue  prototype,
int  length = 0 
)

Creates a QScriptValue that wraps a native (C++) function. fun must be a C++ function with signature QScriptEngine::FunctionSignature. length is the number of arguments that fun expects; this becomes the length property of the created QScriptValue.

Note that length only gives an indication of the number of arguments that the function expects; an actual invocation of a function can include any number of arguments. You can check the argumentCount() of the QScriptContext associated with the invocation to determine the actual number of arguments passed.

A prototype property is automatically created for the resulting function object, to provide for the possibility that the function will be used as a constructor.

By combining newFunction() and the property flags QScriptValue::PropertyGetter and QScriptValue::PropertySetter, you can create script object properties that behave like normal properties in script code, but are in fact accessed through functions (analogous to how properties work in Qt's Property System). Example:

static QScriptValue getSetFoo(QScriptContext *context, QScriptEngine *engine)

{

QScriptValue callee = context->callee();

if (context->argumentCount() == 1) // writing?

callee.setProperty("value", context->argument(0));

return callee.property("value");

}

....

QScriptValue object = engine.newObject();

object.setProperty("foo", engine.newFunction(getSetFoo),

QScriptValue::PropertyGetter | QScriptValue::PropertySetter);

When the property foo of the script object is subsequently accessed in script code, getSetFoo() will be invoked to handle the access. In this particular case, we chose to store the "real" value of foo as a property of the accessor function itself; you are of course free to do whatever you like in this function.

In the above example, a single native function was used to handle both reads and writes to the property; the argument count is used to determine if we are handling a read or write. You can also use two separate functions; just specify the relevant flag (QScriptValue::PropertyGetter or QScriptValue::PropertySetter) when setting the property, e.g.:

QScriptValue object = engine.newObject();

object.setProperty("foo", engine.newFunction(getFoo), QScriptValue::PropertyGetter);

object.setProperty("foo", engine.newFunction(setFoo), QScriptValue::PropertySetter);

See also QScriptValue::call().

new QScriptValue QtScript.QScriptEngine.NewFunction ( Global.FuncQScriptValueQScriptContextQScriptEngine  signature,
int  length = 0 
)

Creates a QScriptValue that wraps a native (C++) function. fun must be a C++ function with signature QScriptEngine::FunctionSignature. length is the number of arguments that fun expects; this becomes the length property of the created QScriptValue.

Note that length only gives an indication of the number of arguments that the function expects; an actual invocation of a function can include any number of arguments. You can check the argumentCount() of the QScriptContext associated with the invocation to determine the actual number of arguments passed.

A prototype property is automatically created for the resulting function object, to provide for the possibility that the function will be used as a constructor.

By combining newFunction() and the property flags QScriptValue::PropertyGetter and QScriptValue::PropertySetter, you can create script object properties that behave like normal properties in script code, but are in fact accessed through functions (analogous to how properties work in Qt's Property System). Example:

static QScriptValue getSetFoo(QScriptContext *context, QScriptEngine *engine)

{

QScriptValue callee = context->callee();

if (context->argumentCount() == 1) // writing?

callee.setProperty("value", context->argument(0));

return callee.property("value");

}

....

QScriptValue object = engine.newObject();

object.setProperty("foo", engine.newFunction(getSetFoo),

QScriptValue::PropertyGetter | QScriptValue::PropertySetter);

When the property foo of the script object is subsequently accessed in script code, getSetFoo() will be invoked to handle the access. In this particular case, we chose to store the "real" value of foo as a property of the accessor function itself; you are of course free to do whatever you like in this function.

In the above example, a single native function was used to handle both reads and writes to the property; the argument count is used to determine if we are handling a read or write. You can also use two separate functions; just specify the relevant flag (QScriptValue::PropertyGetter or QScriptValue::PropertySetter) when setting the property, e.g.:

QScriptValue object = engine.newObject();

object.setProperty("foo", engine.newFunction(getFoo), QScriptValue::PropertyGetter);

object.setProperty("foo", engine.newFunction(setFoo), QScriptValue::PropertySetter);

See also QScriptValue::call().

new QScriptValue QtScript.QScriptEngine.NewObject ( )

Creates a QtScript object of class Object.

The prototype of the created object will be the Object prototype object.

See also newArray() and QScriptValue::setProperty().

new QScriptValue QtScript.QScriptEngine.NewObject ( QScriptClass  scriptClass)

Creates a QtScript object of class Object.

The prototype of the created object will be the Object prototype object.

See also newArray() and QScriptValue::setProperty().

new QScriptValue QtScript.QScriptEngine.NewObject ( QScriptClass  scriptClass,
QScriptValue  data 
)

Creates a QtScript object of class Object.

The prototype of the created object will be the Object prototype object.

See also newArray() and QScriptValue::setProperty().

new QScriptValue QtScript.QScriptEngine.NewQMetaObject ( QMetaObject  metaObject)

Creates a QtScript object that represents a QObject class, using the the given metaObject and constructor ctor.

Enums of metaObject (declared with Q_ENUMS) are available as properties of the created QScriptValue. When the class is called as a function, ctor will be called to create a new instance of the class.

Example:

QScriptValue mySpecialQObjectConstructor(QScriptContext *context,

QScriptEngine *engine)

{

QObject *parent = context->argument(0).toQObject();

QObject *object = new QObject(parent);

return engine->newQObject(object, QScriptEngine::ScriptOwnership);

}

...

QScriptValue ctor = engine.newFunction(mySpecialQObjectConstructor);

QScriptValue metaObject = engine.newQMetaObject(&QObject::staticMetaObject, ctor);

engine.globalObject().setProperty("QObject", metaObject);

QScriptValue result = engine.evaluate("new QObject()");

See also newQObject() and scriptValueFromQMetaObject().

new QScriptValue QtScript.QScriptEngine.NewQMetaObject ( QMetaObject  metaObject,
QScriptValue  ctor 
)

Creates a QtScript object that represents a QObject class, using the the given metaObject and constructor ctor.

Enums of metaObject (declared with Q_ENUMS) are available as properties of the created QScriptValue. When the class is called as a function, ctor will be called to create a new instance of the class.

Example:

QScriptValue mySpecialQObjectConstructor(QScriptContext *context,

QScriptEngine *engine)

{

QObject *parent = context->argument(0).toQObject();

QObject *object = new QObject(parent);

return engine->newQObject(object, QScriptEngine::ScriptOwnership);

}

...

QScriptValue ctor = engine.newFunction(mySpecialQObjectConstructor);

QScriptValue metaObject = engine.newQMetaObject(&QObject::staticMetaObject, ctor);

engine.globalObject().setProperty("QObject", metaObject);

QScriptValue result = engine.evaluate("new QObject()");

See also newQObject() and scriptValueFromQMetaObject().

new QScriptValue QtScript.QScriptEngine.NewQObject ( QScriptValue  scriptObject,
QObject  qtObject,
QScriptEngine.ValueOwnership  ownership = QScriptEngine.ValueOwnership.QtOwnership,
QScriptEngine.QObjectWrapOption  options = 0 
)

Creates a QtScript object that wraps the given QObject object, using the given ownership. The given options control various aspects of the interaction with the resulting script object.

Signals and slots, properties and children of object are available as properties of the created QScriptValue. For more information, see the QtScript documentation.

If object is a null pointer, this function returns nullValue().

If a default prototype has been registered for the object's class (or its superclass, recursively), the prototype of the new script object will be set to be that default prototype.

If the given object is deleted outside of QtScript's control, any attempt to access the deleted QObject's members through the QtScript wrapper object (either by script code or C++) will result in a script exception.

See also QScriptValue::toQObject() and reportAdditionalMemoryCost().

new QScriptValue QtScript.QScriptEngine.NewQObject ( QObject object,
QScriptEngine.ValueOwnership  ownership = QScriptEngine.ValueOwnership.QtOwnership,
QScriptEngine.QObjectWrapOption  options = 0 
)

Creates a QtScript object that wraps the given QObject object, using the given ownership. The given options control various aspects of the interaction with the resulting script object.

Signals and slots, properties and children of object are available as properties of the created QScriptValue. For more information, see the QtScript documentation.

If object is a null pointer, this function returns nullValue().

If a default prototype has been registered for the object's class (or its superclass, recursively), the prototype of the new script object will be set to be that default prototype.

If the given object is deleted outside of QtScript's control, any attempt to access the deleted QObject's members through the QtScript wrapper object (either by script code or C++) will result in a script exception.

See also QScriptValue::toQObject() and reportAdditionalMemoryCost().

new QScriptValue QtScript.QScriptEngine.NewRegExp ( QRegExp  regexp)

Creates a QtScript object of class RegExp with the given regexp.

See also QScriptValue::toRegExp().

new QScriptValue QtScript.QScriptEngine.NewRegExp ( string  pattern,
string  flags 
)

Creates a QtScript object of class RegExp with the given pattern and flags.

The legal flags are 'g' (global), 'i' (ignore case), and 'm' (multiline).

new QScriptValue QtScript.QScriptEngine.NewVariant ( object  value)

Creates a QtScript object holding the given variant value.

If a default prototype has been registered with the meta type id of value, then the prototype of the created object will be that prototype; otherwise, the prototype will be the Object prototype object.

See also setDefaultPrototype(), QScriptValue::toVariant(), and reportAdditionalMemoryCost().

new QScriptValue QtScript.QScriptEngine.NewVariant ( QScriptValue object,
object  value 
)

This is an overloaded function.

Initializes the given Qt Script object to hold the given variant value, and returns the object.

This function enables you to "promote" a plain Qt Script object (created by the newObject() function) to a variant, or to replace the variant contained inside an object previously created by the newVariant() function.

The prototype() of the object will remain unchanged.

If object is not an object, this function behaves like the normal newVariant(), i.e. it creates a new script object and returns it.

This function is useful when you want to provide a script constructor for a C++ type. If your constructor is invoked in a new expression (QScriptContext::isCalledAsConstructor() returns true), you can pass QScriptContext::thisObject() (the default constructed script object) to this function to initialize the new object.

This function was introduced in Qt 4.4.

See also reportAdditionalMemoryCost().

new QScriptValue QtScript.QScriptEngine.NullValue ( )

Returns a QScriptValue of the primitive type Null.

See also undefinedValue().

new QScriptValue QtScript.QScriptEngine.ObjectById ( long  id)
new void QtScript.QScriptEngine.OnSignalHandlerException ( QScriptValue  exception)
protected

This signal is emitted when a script function connected to a signal causes an exception.

This function was introduced in Qt 4.4.

See also qScriptConnect().

new void QtScript.QScriptEngine.PopContext ( )

Pops the current execution context and restores the previous one. This function must be used in conjunction with pushContext().

See also pushContext().

new QScriptContext QtScript.QScriptEngine.PushContext ( )

Enters a new execution context and returns the associated QScriptContext object.

Once you are done with the context, you should call popContext() to restore the old context.

By default, the `this' object of the new context is the Global Object. The context's callee() will be invalid.

This function is useful when you want to evaluate script code as if it were the body of a function. You can use the context's activationObject() to initialize local variables that will be available to scripts. Example:

QScriptEngine engine;

QScriptContext *context = engine.pushContext();

context->activationObject().setProperty("myArg", 123);

engine.evaluate("var tmp = myArg + 42");

...

engine.popContext();

In the above example, the new variable "tmp" defined in the script will be local to the context; in other words, the script doesn't have any effect on the global environment.

Returns 0 in case of stack overflow

See also popContext().

new void QtScript.QScriptEngine.ReportAdditionalMemoryCost ( int  size)

Reports an additional memory cost of the given size, measured in bytes, to the garbage collector.

This function can be called to indicate that a Qt Script object has memory associated with it that isn't managed by Qt Script itself. Reporting the additional cost makes it more likely that the garbage collector will be triggered.

Note that if the additional memory is shared with objects outside the scripting environment, the cost should not be reported, since collecting the Qt Script object would not cause the memory to be freed anyway.

Negative size values are ignored, i.e. this function can't be used to report that the additional memory has been deallocated.

This function was introduced in Qt 4.7.

See also collectGarbage().

new void QtScript.QScriptEngine.SetDefaultPrototype ( int  metaTypeId,
QScriptValue  prototype 
)

Sets the default prototype of the C++ type identified by the given metaTypeId to prototype.

The default prototype provides a script interface for values of type metaTypeId when a value of that type is accessed from script code. Whenever the script engine (implicitly or explicitly) creates a QScriptValue from a value of type metaTypeId, the default prototype will be set as the QScriptValue's prototype.

The prototype object itself may be constructed using one of two principal techniques; the simplest is to subclass QScriptable, which enables you to define the scripting API of the type through QObject properties and slots. Another possibility is to create a script object by calling newObject(), and populate the object with the desired properties (e.g. native functions wrapped with newFunction()).

See also defaultPrototype(), qScriptRegisterMetaType(), QScriptable, and Default Prototypes Example.

new QScriptValue QtScript.QScriptEngine.ToObject ( QScriptValue  value)

Converts the given value to an object, if such a conversion is possible; otherwise returns an invalid QScriptValue. The conversion is performed according to the following table:

Input TypeResult

Undefined An invalid QScriptValue.

Null An invalid QScriptValue.

Boolean A new Boolean object whose internal value is set to the value of the boolean.

Number A new Number object whose internal value is set to the value of the number.

String A new String object whose internal value is set to the value of the string.

Object The result is the object itself (no conversion).

This function was introduced in Qt 4.5.

See also newObject().

new QScriptString QtScript.QScriptEngine.ToStringHandle ( string  str)

Returns a handle that represents the given string, str.

QScriptString can be used to quickly look up properties, and compare property names, of script objects.

This function was introduced in Qt 4.4.

See also QScriptValue::property().

static string QtScript.QScriptEngine.Tr ( string  s,
string  c = null 
)
static
static string QtScript.QScriptEngine.Tr ( string  s,
string  c,
int  n 
)
static
static string QtScript.QScriptEngine.TrUtf8 ( string  s,
string  c = null 
)
static
static string QtScript.QScriptEngine.TrUtf8 ( string  s,
string  c,
int  n 
)
static
new QScriptValue QtScript.QScriptEngine.UncaughtException ( )

Returns the current uncaught exception, or an invalid QScriptValue if there is no uncaught exception.

The exception value is typically an Error object; in that case, you can call toString() on the return value to obtain an error message.

See also hasUncaughtException() and uncaughtExceptionLineNumber().

new System.Collections.Generic.List<string> QtScript.QScriptEngine.UncaughtExceptionBacktrace ( )

Returns a human-readable backtrace of the last uncaught exception.

It is in the form <function-name>()&lt;file-name>:<line-number>.

See also uncaughtException().

new int QtScript.QScriptEngine.UncaughtExceptionLineNumber ( )

Returns the line number where the last uncaught exception occurred.

Line numbers are 1-based, unless a different base was specified as the second argument to evaluate().

See also hasUncaughtException().

new QScriptValue QtScript.QScriptEngine.UndefinedValue ( )

Returns a QScriptValue of the primitive type Undefined.

See also nullValue().

Property Documentation

new QScriptEngineAgent QtScript.QScriptEngine.Agent
getset

Returns the agent currently installed on this engine, or 0 if no agent is installed.

This function was introduced in Qt 4.4.

Installs the given agent on this engine. The agent will be notified of various events pertaining to script execution. This is useful when you want to find out exactly what the engine is doing, e.g. when evaluate() is called. The agent interface is the basis of tools like debuggers and profilers.

The engine maintains ownership of the agent.

Calling this function will replace the existing agent, if any.

This function was introduced in Qt 4.4.

new IQScriptEngineSignals QtScript.QScriptEngine.Emit
getprotected
new QScriptValue QtScript.QScriptEngine.GlobalObject
getset

Returns this engine's Global Object.

By default, the Global Object contains the built-in objects that are part of ECMA-262, such as Math, Date and String. Additionally, you can set properties of the Global Object to make your own extensions available to all script code. Non-local variables in script code will be created as properties of the Global Object, as well as local variables in global code.

Sets this engine's Global Object to be the given object. If object is not a valid script object, this function does nothing.

When setting a custom global object, you may want to use QScriptValueIterator to copy the properties of the standard Global Object; alternatively, you can set the internal prototype of your custom object to be the original Global Object.

This function was introduced in Qt 4.5.

new int QtScript.QScriptEngine.ProcessEventsInterval
getset

Returns the interval in milliseconds between calls to QCoreApplication::processEvents() while the interpreter is running.

Sets the interval between calls to QCoreApplication::processEvents to interval milliseconds.

While the interpreter is running, all event processing is by default blocked. This means for instance that the gui will not be updated and timers will not be fired. To allow event processing during interpreter execution one can specify the processing interval to be a positive value, indicating the number of milliseconds between each time QCoreApplication::processEvents() is called.

The default value is -1, which disables event processing during interpreter execution.

You can use QCoreApplication::postEvent() to post an event that performs custom processing at the next interval. For example, you could keep track of the total running time of the script and call abortEvaluation() when you detect that the script has been running for a long time without completing.

Slot<QScriptValue> QtScript.QScriptEngine.SignalHandlerException
addremove

This signal is emitted when a script function connected to a signal causes an exception.

This function was introduced in Qt 4.4.

See also qScriptConnect().

new QMetaObject QtScript.QScriptEngine.StaticMetaObject
staticget