24 #ifndef QSCRIPTENGINE_H 25 #define QSCRIPTENGINE_H 27 #include <QtCore/qmetatype.h> 29 #include <QtCore/qvariant.h> 30 #include <QtCore/qsharedpointer.h> 33 #include <QtCore/qobject.h> 35 #include <QtCore/qobjectdefs.h> 38 #include <QtScript/qscriptvalue.h> 39 #include <QtScript/qscriptcontext.h> 40 #include <QtScript/qscriptstring.h> 41 #include <QtScript/qscriptprogram.h> 62 #endif // QT_NO_QOBJECT 88 int errorLineNumber()
const;
89 int errorColumnNumber()
const;
105 #ifndef QT_NO_QOBJECT 109 #ifndef QT_NO_QOBJECT 120 ExcludeChildObjects = 0x0001,
121 ExcludeSuperClassMethods = 0x0002,
122 ExcludeSuperClassProperties = 0x0004,
123 ExcludeSuperClassContents = 0x0006,
124 SkipMethodsInEnumeration = 0x0008,
125 ExcludeDeleteLater = 0x0010,
126 ExcludeSlots = 0x0020,
128 AutoCreateDynamicProperties = 0x0100,
129 PreferExistingWrapperObject = 0x0200
134 #ifndef QT_NO_QOBJECT 135 explicit QScriptEngine(
QObject *parent);
137 virtual ~QScriptEngine();
146 bool canEvaluate(
const QString &program)
const;
153 bool isEvaluating()
const;
156 bool hasUncaughtException()
const;
158 int uncaughtExceptionLineNumber()
const;
160 void clearExceptions();
166 typedef QScriptValue (*FunctionWithArgSignature)(QScriptContext *, QScriptEngine *,
void *);
168 QScriptValue newFunction(FunctionSignature signature,
int length = 0);
171 QScriptValue newFunction(FunctionWithArgSignature signature,
void *arg);
188 #ifndef QT_NO_QOBJECT 190 const QObjectWrapOptions &options = 0);
193 const QObjectWrapOptions &options = 0);
197 template <
class T>
QScriptValue scriptValueFromQMetaObject();
199 #endif // QT_NO_QOBJECT 207 typedef QScriptValue (*MarshalFunction)(QScriptEngine *,
const void *);
212 template <
typename T>
217 template <
typename T>
223 void installTranslatorFunctions(
const QScriptValue &
object = QScriptValue());
225 QScriptValue importExtension(
const QString &extension);
229 void collectGarbage();
230 void reportAdditionalMemoryCost(
int size);
232 void setProcessEventsInterval(
int interval);
233 int processEventsInterval()
const;
239 QScriptValue toObject(
const QScriptValue &value);
241 QScriptValue objectById(
qint64 id)
const;
243 #ifndef QT_NO_QOBJECT 245 void signalHandlerException(
const QScriptValue &exception);
251 bool convert(
const QScriptValue &value,
int type,
void *ptr);
252 static bool convertV2(
const QScriptValue &value,
int type,
void *ptr);
254 void registerCustomType(
int type, MarshalFunction mf, DemarshalFunction df,
258 int, MarshalFunction, DemarshalFunction,
const QScriptValue &);
268 QScriptEngine(QScriptEnginePrivate &dd);
270 QScriptEngine(QScriptEnginePrivate &dd,
QObject *parent = 0);
276 #ifndef QT_NO_QOBJECT 281 #ifndef QT_NO_QOBJECT 283 #define Q_SCRIPT_DECLARE_QMETAOBJECT(T, _Arg1) \ 284 template<> inline QScriptValue qscriptQMetaObjectConstructor<T>(QScriptContext *ctx, QScriptEngine *eng, T *) \ 286 _Arg1 arg1 = qscriptvalue_cast<_Arg1> (ctx->argument(0)); \ 287 T* t = new T(arg1); \ 288 if (ctx->isCalledAsConstructor()) \ 289 return eng->newQObject(ctx->thisObject(), t, QScriptEngine::AutoOwnership); \ 290 QScriptValue o = eng->newQObject(t, QScriptEngine::AutoOwnership); \ 291 o.setPrototype(ctx->callee().property(QString::fromLatin1("prototype"))); \ 297 typedef QScriptValue(*ConstructPtr)(QScriptContext *, QScriptEngine *, T *);
298 ConstructPtr cptr = qscriptQMetaObjectConstructor<T>;
299 return newQMetaObject(&T::staticMetaObject,
300 newFunction(reinterpret_cast<FunctionWithArgSignature>(cptr), 0));
306 QScriptEngine *engine
312 return engine->scriptValueFromQMetaObject<T>();
316 #endif // QT_NO_QOBJECT 323 return engine->
create(type, ptr);
326 template <
typename T>
347 const int id = qMetaTypeId<T>();
352 return qvariant_cast<T>(value.
toVariant());
360 return value.toVariant();
364 template <
typename T>
382 QScriptValue (*toScriptValue)(QScriptEngine *,
const T &t),
390 const int id = qRegisterMetaType<T>();
393 eng,
id, reinterpret_cast<QScriptEngine::MarshalFunction>(toScriptValue),
400 template <
class Container>
404 typename Container::const_iterator begin = cont.begin();
405 typename Container::const_iterator
end = cont.end();
406 typename Container::const_iterator
it;
408 for (it = begin, i = 0; it !=
end; ++
it, ++i)
413 template <
class Container>
417 for (
quint32 i = 0; i < len; ++i) {
419 cont.push_back(qscriptvalue_cast<typename Container::value_type>(item));
425 QScriptEngine *engine,
436 #ifndef QT_NO_QOBJECT 443 #endif // QT_NO_QOBJECT 451 #endif // QSCRIPTENGINE_H The QVariant class acts like a union for the most common Qt data types.
void(* DemarshalFunction)(const QScriptValue &, void *)
The QScriptContext class represents a Qt Script function invocation.
QScriptValue property(const QString &name, const ResolveFlags &mode=ResolvePrototype) const
Returns the value of this QScriptValue's property with the given name, using the given mode to resolv...
T qscriptvalue_cast(const QScriptValue &)
#define QT_END_NAMESPACE
This macro expands to.
The QScriptClass class provides an interface for defining custom behavior of (a class of) Qt Script o...
The QRegExp class provides pattern matching using regular expressions.
#define Q_DECLARE_FLAGS(Flags, Enum)
The Q_DECLARE_FLAGS() macro expands to.
#define it(className, varName)
Q_SCRIPT_EXPORT bool qScriptDisconnect(QObject *sender, const char *signal, const QScriptValue &receiver, const QScriptValue &function)
QT_DEPRECATED QScriptValue qScriptValueFromQMetaObject(QScriptEngine *engine)
static Expression::Ptr create(Expression *const expr, const YYLTYPE &sourceLocator, const ParserContext *const parseInfo)
QScriptValue toScriptValue(const T &value)
Creates a QScriptValue with the given value.
void registerCustomType(int type, MarshalFunction mf, DemarshalFunction df, const QScriptValue &prototype)
QT_DEPRECATED T qScriptValueToValue(const QScriptValue &value)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
#define Q_PRIVATE_SLOT(d, signature)
QScriptValue qScriptValueFromValue< QVariant >(QScriptEngine *engine, const QVariant &v)
long ASN1_INTEGER_get ASN1_INTEGER * a
QScriptValue qScriptValueFromValue(QScriptEngine *engine, const T &value)
The QString class provides a Unicode character string.
The QObject class is the base class of all Qt objects.
QScriptValue qScriptValueFromValue(QScriptEngine *, const T &)
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
The QScriptString class acts as a handle to "interned" strings in a QScriptEngine.
T qscriptvalue_cast(const QScriptValue &value)
Returns the given value converted to the template type T.
QScriptValue qScriptValueFromSequence(QScriptEngine *eng, const Container &cont)
The QScriptEngine class provides an environment for evaluating Qt Script code.
#define QT_BEGIN_NAMESPACE
This macro expands to.
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
The Q_DECLARE_OPERATORS_FOR_FLAGS() macro declares global operator|() functions for Flags...
QVariant toVariant() const
Returns the QVariant value of this QScriptValue, if it can be converted to a QVariant; otherwise retu...
The QStringList class provides a list of strings.
void qScriptRegisterMetaType_helper(QScriptEngine *eng, int type, QScriptEngine::MarshalFunction mf, QScriptEngine::DemarshalFunction df, const QScriptValue &prototype)
static const char * data(const QByteArray &arr)
The QScriptSyntaxCheckResult class provides the result of a script syntax check.
ValueOwnership
This enum specifies the ownership when wrapping a C++ value, e.
bool qscriptvalue_cast_helper(const QScriptValue &value, int type, void *ptr)
quint32 toUInt32() const
Returns the unsigned 32-bit integer value of this QScriptValue, using the conversion rules described ...
const T * ptr(const T &t)
The State element defines configurations of objects and properties.
bool isVariant() const
Returns true if this QScriptValue is a variant value; otherwise returns false.
static bool convertV2(const QScriptValue &value, int type, void *ptr)
int qScriptRegisterSequenceMetaType(QScriptEngine *engine, const QScriptValue &prototype=QScriptValue())
static bool convert(const QVariant::Private *d, QVariant::Type t, void *result, bool *ok)
QScriptValue qscriptQMetaObjectConstructor(QScriptContext *, QScriptEngine *, T *)
static QByteArray prototype(const QList< QByteArray > ¶meterTypes, const QList< QByteArray > ¶meterNames, bool *ok)
QObjectWrapOption
These flags specify options when wrapping a QObject pointer with newQObject().
void setProperty(const QString &name, const QScriptValue &value, const PropertyFlags &flags=KeepExistingFlags)
Sets the value of this QScriptValue's property with the given name to the given value.
The QDateTime class provides date and time functions.
Q_SCRIPT_EXPORT bool qScriptConnect(QObject *sender, const char *signal, const QScriptValue &receiver, const QScriptValue &function)
QScriptValue scriptValueFromQMetaObject()
Creates a QScriptValue that represents the Qt class T.
int qScriptRegisterMetaType(QScriptEngine *eng, QScriptValue(*toScriptValue)(QScriptEngine *, const T &t), void(*fromScriptValue)(const QScriptValue &, T &t), const QScriptValue &prototype=QScriptValue())
static JSAgentWatchData fromScriptValue(const QString &expression, const QScriptValue &value)
QScriptValue create(int type, const void *ptr)
QScriptValue(* MarshalFunction)(QScriptEngine *, const void *)
void qScriptValueToSequence(const QScriptValue &value, Container &cont)
The QScriptProgram class encapsulates a Qt Script program.
#define Q_DECLARE_PRIVATE(Class)
QScriptValue newArray(uint length=0)
Creates a QtScript object of class Array with the given length.
static const KeyPair *const end
T fromScriptValue(const QScriptValue &value)
Returns the given value converted to the template type T.
The QScriptValue class acts as a container for the Qt Script data types.
static QString fileName(const QString &fileUrl)
QExplicitlySharedDataPointer< QScriptSyntaxCheckResultPrivate > d_ptr
The QScriptEngineAgent class provides an interface to report events pertaining to QScriptEngine execu...
QScriptValue qScriptValueFromValue_helper(QScriptEngine *engine, int type, const void *ptr)