Qt 4.8
Classes | Macros | Functions
qscriptengine.h File Reference
#include <QtCore/qmetatype.h>
#include <QtCore/qvariant.h>
#include <QtCore/qsharedpointer.h>
#include <QtCore/qobject.h>
#include <QtScript/qscriptvalue.h>
#include <QtScript/qscriptcontext.h>
#include <QtScript/qscriptstring.h>
#include <QtScript/qscriptprogram.h>

Go to the source code of this file.

Classes

class  QScriptEngine
 The QScriptEngine class provides an environment for evaluating Qt Script code. More...
 
class  QScriptSyntaxCheckResult
 The QScriptSyntaxCheckResult class provides the result of a script syntax check. More...
 

Macros

#define Q_SCRIPT_DECLARE_QMETAOBJECT(T, _Arg1)
 

Functions

Q_SCRIPT_EXPORT bool qScriptConnect (QObject *sender, const char *signal, const QScriptValue &receiver, const QScriptValue &function)
 
Q_SCRIPT_EXPORT bool qScriptDisconnect (QObject *sender, const char *signal, const QScriptValue &receiver, const QScriptValue &function)
 
template<class T >
QScriptValue qscriptQMetaObjectConstructor (QScriptContext *, QScriptEngine *, T *)
 
template<typename T >
int qScriptRegisterMetaType (QScriptEngine *eng, QScriptValue(*toScriptValue)(QScriptEngine *, const T &t), void(*fromScriptValue)(const QScriptValue &, T &t), const QScriptValue &prototype=QScriptValue())
 
void qScriptRegisterMetaType_helper (QScriptEngine *eng, int type, QScriptEngine::MarshalFunction mf, QScriptEngine::DemarshalFunction df, const QScriptValue &prototype)
 
template<typename T >
int qScriptRegisterSequenceMetaType (QScriptEngine *engine, const QScriptValue &prototype=QScriptValue())
 
template<typename T >
qscriptvalue_cast (const QScriptValue &)
 
template<>
QVariant qscriptvalue_cast< QVariant > (const QScriptValue &value)
 
bool qscriptvalue_cast_helper (const QScriptValue &value, int type, void *ptr)
 
template<class T >
QT_DEPRECATED QScriptValue qScriptValueFromQMetaObject (QScriptEngine *engine)
 
template<class Container >
QScriptValue qScriptValueFromSequence (QScriptEngine *eng, const Container &cont)
 
template<typename T >
QScriptValue qScriptValueFromValue (QScriptEngine *, const T &)
 
template<>
QScriptValue qScriptValueFromValue< QVariant > (QScriptEngine *engine, const QVariant &v)
 
QScriptValue qScriptValueFromValue_helper (QScriptEngine *engine, int type, const void *ptr)
 
template<class Container >
void qScriptValueToSequence (const QScriptValue &value, Container &cont)
 
template<typename T >
QT_DEPRECATEDqScriptValueToValue (const QScriptValue &value)
 

Macro Definition Documentation

◆ Q_SCRIPT_DECLARE_QMETAOBJECT

#define Q_SCRIPT_DECLARE_QMETAOBJECT (   T,
  _Arg1 
)
Value:
template<> inline QScriptValue qscriptQMetaObjectConstructor<T>(QScriptContext *ctx, QScriptEngine *eng, T *) \
{ \
_Arg1 arg1 = qscriptvalue_cast<_Arg1> (ctx->argument(0)); \
T* t = new T(arg1); \
if (ctx->isCalledAsConstructor()) \
return eng->newQObject(ctx->thisObject(), t, QScriptEngine::AutoOwnership); \
QScriptValue o = eng->newQObject(t, QScriptEngine::AutoOwnership); \
o.setPrototype(ctx->callee().property(QString::fromLatin1("prototype"))); \
return o; \
}
The QScriptContext class represents a Qt Script function invocation.
T qscriptvalue_cast(const QScriptValue &value)
Returns the given value converted to the template type T.
The QScriptEngine class provides an environment for evaluating Qt Script code.
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
#define ctx
Definition: qgl.cpp:6094
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
Since
4.3

Declares the given QMetaObject. Used in combination with QScriptEngine::scriptValueFromQMetaObject() to make enums and instantiation of QMetaObject available to script code. The constructor generated by this macro takes a single argument of type ArgType; typically the argument is the parent type of the new instance, in which case ArgType is QWidget* or QObject*. Objects created by the constructor will have QScriptEngine::AutoOwnership ownership.

Definition at line 283 of file qscriptengine.h.

Function Documentation

◆ qScriptConnect()

Q_SCRIPT_EXPORT bool qScriptConnect ( QObject sender,
const char *  signal,
const QScriptValue receiver,
const QScriptValue function 
)
related

◆ qScriptDisconnect()

Q_SCRIPT_EXPORT bool qScriptDisconnect ( QObject sender,
const char *  signal,
const QScriptValue receiver,
const QScriptValue function 
)
related

◆ qscriptQMetaObjectConstructor()

template<class T >
QScriptValue qscriptQMetaObjectConstructor ( QScriptContext ,
QScriptEngine ,
T *   
)
inline

Definition at line 57 of file qscriptengine.h.

58 {
59  return QScriptValue();
60 }
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ qScriptRegisterMetaType()

template<typename T >
int qScriptRegisterMetaType ( QScriptEngine eng,
QScriptValue(*)(QScriptEngine *, const T &t)  toScriptValue,
void(*)(const QScriptValue &, T &t)  fromScriptValue,
const QScriptValue prototype = QScriptValue() 
)
related

Definition at line 380 of file qscriptengine.h.

389 {
390  const int id = qRegisterMetaType<T>(); // make sure it's registered
391 
393  eng, id, reinterpret_cast<QScriptEngine::MarshalFunction>(toScriptValue),
394  reinterpret_cast<QScriptEngine::DemarshalFunction>(fromScriptValue),
395  prototype);
396 
397  return id;
398 }
void qScriptRegisterMetaType_helper(QScriptEngine *eng, int type, QScriptEngine::MarshalFunction mf, QScriptEngine::DemarshalFunction df, const QScriptValue &prototype)
static JSAgentWatchData fromScriptValue(const QString &expression, const QScriptValue &value)

◆ qScriptRegisterMetaType_helper()

void qScriptRegisterMetaType_helper ( QScriptEngine eng,
int  type,
QScriptEngine::MarshalFunction  mf,
QScriptEngine::DemarshalFunction  df,
const QScriptValue prototype 
)
inline

Definition at line 371 of file qscriptengine.h.

Referenced by QScriptEngine::fromScriptValue(), and qScriptRegisterMetaType().

375 {
376  eng->registerCustomType(type, mf, df, prototype);
377 }
int type
Definition: qmetatype.cpp:239
void registerCustomType(int type, MarshalFunction mf, DemarshalFunction df, const QScriptValue &prototype)

◆ qScriptRegisterSequenceMetaType()

template<typename T >
int qScriptRegisterSequenceMetaType ( QScriptEngine engine,
const QScriptValue prototype = QScriptValue() 
)
related

Definition at line 424 of file qscriptengine.h.

431 {
432  return qScriptRegisterMetaType<T>(engine, qScriptValueFromSequence,
434 }
void qScriptValueToSequence(const QScriptValue &value, Container &container)
Copies the elements in the sequence specified by value to the given container of template type Contai...
QScriptValue qScriptValueFromSequence(QScriptEngine *engine, const Container &container)
static QByteArray prototype(const QList< QByteArray > &parameterTypes, const QList< QByteArray > &parameterNames, bool *ok)
Definition: qaxserver.cpp:685

◆ qscriptvalue_cast()

template<typename T >
T qscriptvalue_cast ( const QScriptValue value)
related

Definition at line 344 of file qscriptengine.h.

Referenced by Node::attributes(), Node::childNodes(), Document::documentElement(), Node::firstChild(), QScriptEngine::fromScriptValue(), Text::isElementContentWhitespace(), Node::lastChild(), NamedNodeMap::length(), NodeList::length(), CharacterData::length(), Attr::name(), Node::nextSibling(), Node::nodeName(), Node::nodeType(), Node::nodeValue(), Attr::ownerElement(), Node::parentNode(), Node::previousSibling(), QDeclarativeSqlQueryScriptClass::property(), NamedNodeMapClass::property(), NodeListClass::property(), qmlsqldatabase_change_version(), qmlsqldatabase_executeSql(), qmlsqldatabase_item(), qmlsqldatabase_transaction_shared(), qScriptValueToValue(), NamedNodeMapClass::queryProperty(), NodeListClass::queryProperty(), QDeclarativeSqlQueryScriptClass::setProperty(), QScriptDebuggerBackendPrivate::trace(), Attr::value(), Text::wholeText(), Document::xmlEncoding(), Document::xmlStandalone(), and Document::xmlVersion().

345 {
346  T t;
347  const int id = qMetaTypeId<T>();
348 
349  if (qscriptvalue_cast_helper(value, id, &t))
350  return t;
351  else if (value.isVariant())
352  return qvariant_cast<T>(value.toVariant());
353 
354  return T();
355 }
QVariant toVariant() const
Returns the QVariant value of this QScriptValue, if it can be converted to a QVariant; otherwise retu...
bool qscriptvalue_cast_helper(const QScriptValue &value, int type, void *ptr)
bool isVariant() const
Returns true if this QScriptValue is a variant value; otherwise returns false.

◆ qscriptvalue_cast< QVariant >()

template<>
QVariant qscriptvalue_cast< QVariant > ( const QScriptValue value)
inline

Definition at line 358 of file qscriptengine.h.

359 {
360  return value.toVariant();
361 }
QVariant toVariant() const
Returns the QVariant value of this QScriptValue, if it can be converted to a QVariant; otherwise retu...

◆ qscriptvalue_cast_helper()

bool qscriptvalue_cast_helper ( const QScriptValue value,
int  type,
void *  ptr 
)
inline

Definition at line 338 of file qscriptengine.h.

Referenced by QScriptEngine::fromScriptValue(), and qscriptvalue_cast().

339 {
340  return QScriptEngine::convertV2(value, type, ptr);
341 }
int type
Definition: qmetatype.cpp:239
const T * ptr(const T &t)
static bool convertV2(const QScriptValue &value, int type, void *ptr)

◆ qScriptValueFromQMetaObject()

template<class T >
QT_DEPRECATED QScriptValue qScriptValueFromQMetaObject ( QScriptEngine engine)
related

Definition at line 305 of file qscriptengine.h.

311 {
312  return engine->scriptValueFromQMetaObject<T>();
313 }
QScriptValue scriptValueFromQMetaObject()
Creates a QScriptValue that represents the Qt class T.

◆ qScriptValueFromSequence()

template<class Container >
QScriptValue qScriptValueFromSequence ( QScriptEngine eng,
const Container &  cont 
)
related

Definition at line 401 of file qscriptengine.h.

Referenced by qScriptRegisterSequenceMetaType().

402 {
403  QScriptValue a = eng->newArray();
404  typename Container::const_iterator begin = cont.begin();
405  typename Container::const_iterator end = cont.end();
406  typename Container::const_iterator it;
407  quint32 i;
408  for (it = begin, i = 0; it != end; ++it, ++i)
409  a.setProperty(i, eng->toScriptValue(*it));
410  return a;
411 }
#define it(className, varName)
QScriptValue toScriptValue(const T &value)
Creates a QScriptValue with the given value.
long ASN1_INTEGER_get ASN1_INTEGER * a
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.
unsigned int quint32
Definition: qglobal.h:938
QScriptValue newArray(uint length=0)
Creates a QtScript object of class Array with the given length.
static const KeyPair *const end
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ qScriptValueFromValue()

template<typename T >
QScriptValue qScriptValueFromValue ( QScriptEngine engine,
const T &  t 
)
related

Definition at line 327 of file qscriptengine.h.

Referenced by QScriptEngine::toScriptValue(), and QScriptDebuggerBackend::traceFunction().

328 {
329  return qScriptValueFromValue_helper(engine, qMetaTypeId<T>(), &t);
330 }
QScriptValue qScriptValueFromValue_helper(QScriptEngine *engine, int type, const void *ptr)

◆ qScriptValueFromValue< QVariant >()

template<>
QScriptValue qScriptValueFromValue< QVariant > ( QScriptEngine engine,
const QVariant v 
)
inline

Definition at line 333 of file qscriptengine.h.

334 {
335  return qScriptValueFromValue_helper(engine, v.userType(), v.data());
336 }
void * data()
Definition: qvariant.cpp:3077
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
QScriptValue qScriptValueFromValue_helper(QScriptEngine *engine, int type, const void *ptr)

◆ qScriptValueFromValue_helper()

QScriptValue qScriptValueFromValue_helper ( QScriptEngine engine,
int  type,
const void *  ptr 
)
inline

Definition at line 318 of file qscriptengine.h.

Referenced by QScriptEngine::fromScriptValue(), qScriptValueFromValue(), and qScriptValueFromValue< QVariant >().

319 {
320  if (!engine)
321  return QScriptValue();
322 
323  return engine->create(type, ptr);
324 }
int type
Definition: qmetatype.cpp:239
const T * ptr(const T &t)
QScriptValue create(int type, const void *ptr)
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ qScriptValueToSequence()

template<class Container >
void qScriptValueToSequence ( const QScriptValue value,
Container &  cont 
)
related

Definition at line 414 of file qscriptengine.h.

Referenced by QScriptDebuggerScriptedConsoleCommand::parse(), and qScriptRegisterSequenceMetaType().

415 {
416  quint32 len = value.property(QLatin1String("length")).toUInt32();
417  for (quint32 i = 0; i < len; ++i) {
418  QScriptValue item = value.property(i);
419  cont.push_back(qscriptvalue_cast<typename Container::value_type>(item));
420  }
421 }
QScriptValue property(const QString &name, const ResolveFlags &mode=ResolvePrototype) const
Returns the value of this QScriptValue&#39;s property with the given name, using the given mode to resolv...
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
quint32 toUInt32() const
Returns the unsigned 32-bit integer value of this QScriptValue, using the conversion rules described ...
unsigned int quint32
Definition: qglobal.h:938
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57

◆ qScriptValueToValue()

template<typename T >
QT_DEPRECATED T qScriptValueToValue ( const QScriptValue value)
related

Definition at line 365 of file qscriptengine.h.

366 {
367  return qscriptvalue_cast<T>(value);
368 }
T qscriptvalue_cast(const QScriptValue &value)
Returns the given value converted to the template type T.