- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

Classes | Defines | 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 | QScriptSyntaxCheckResult
class | QScriptEngine
## Defines
#define | Q_SCRIPT_DECLARE_QMETAOBJECT(T, _Arg1)
## Functions
template<class T >
QScriptValue | qscriptQMetaObjectConstructor (QScriptContext *, QScriptEngine *, T *)
template<typename T >
QScriptValue | qScriptValueFromValue (QScriptEngine *, const T &)
template<typename T >
T | qScriptValueToValue (const QScriptValue &)
template<class T >
QScriptValue | qScriptValueFromQMetaObject (QScriptEngine *engine, T *=0)
QScriptValue | qScriptValueFromValue_helper (QScriptEngine *engine, int type, const void *ptr)
template<>
QScriptValue | qScriptValueFromValue< QVariant > (QScriptEngine *engine, const QVariant &v)
bool | qscriptvalue_cast_helper (const QScriptValue &value, int type, void *ptr)
template<typename T >
T | qscriptvalue_cast (const QScriptValue &value)
template<>
QVariant | qscriptvalue_cast< QVariant > (const QScriptValue &value)
void | qScriptRegisterMetaType_helper (QScriptEngine *eng, int type, QScriptEngine::MarshalFunction mf, QScriptEngine::DemarshalFunction df, const QScriptValue &prototype)
template<typename T >
int | qScriptRegisterMetaType (QScriptEngine *eng, QScriptValue(*toScriptValue)(QScriptEngine *, const T &t), void(*fromScriptValue)(const QScriptValue &, T &t), const QScriptValue &prototype=QScriptValue(), T *=0)
template<class Container >
QScriptValue | qScriptValueFromSequence (QScriptEngine *eng, const Container &cont)
template<class Container >
void | qScriptValueToSequence (const QScriptValue &value, Container &cont)
template<typename T >
int | qScriptRegisterSequenceMetaType (QScriptEngine *engine, const QScriptValue &prototype=QScriptValue(), T *=0)
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)

## Define Documentation

#define Q_SCRIPT_DECLARE_QMETAOBJECT | ( |  | T,
|  |  | _Arg1
| ) |  |

Search for all occurrences
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; \
    }

Definition at line 302 of file qscriptengine.h.

## Function Documentation

QScriptValue qscriptQMetaObjectConstructor | ( | QScriptContext * | ,
|  | QScriptEngine * | ,
|  | T * |
| ) |  | `[inline]`

Search for all occurrences

Definition at line 57 of file qscriptengine.h.

    {
        return QScriptValue();
    }

QScriptValue qScriptValueFromValue | ( | QScriptEngine * | engine,
|  | const T & | t
| ) |  | `[inline]`

Search for all occurrences

Definition at line 332 of file qscriptengine.h.

    {
        return qScriptValueFromValue_helper(engine, qMetaTypeId<T>(), &t);
    }

T qScriptValueToValue | ( | const QScriptValue & | value | ) | `[inline]`

Search for all occurrences

Definition at line 378 of file qscriptengine.h.

    {
        return qscriptvalue_cast<T>(value);
    }

QScriptValue qScriptValueFromQMetaObject | ( | QScriptEngine * | engine,
|  | T * | = `0`
| ) |  | `[inline]`

Search for all occurrences

Definition at line 289 of file qscriptengine.h.

    {
        typedef QScriptValue(*ConstructPtr)(QScriptContext *, QScriptEngine *, T *);
        ConstructPtr cptr = qscriptQMetaObjectConstructor<T>;
        return engine->newQMetaObject(&T::staticMetaObject,
                                      engine->newFunction(reinterpret_cast<QScriptEngine::FunctionWithArgSignature>(cptr), 0));
    }

QScriptValue qScriptValueFromValue_helper | ( | QScriptEngine * | engine,
|  | int | type,
|  | const void * | ptr
| ) |  | `[inline]`

Search for all occurrences

Definition at line 323 of file qscriptengine.h.

    {
        if (!engine)
            return QScriptValue();

        return engine->create(type, ptr);
    }

QScriptValue qScriptValueFromValue< QVariant > | ( | QScriptEngine * | engine,
|  | const QVariant & | v
| ) |  | `[inline]`

Search for all occurrences

Definition at line 338 of file qscriptengine.h.

    {
        QScriptValue result = qScriptValueFromValue_helper(engine, v.userType(), v.data());
        if (!result.isValid())
            result = engine->newVariant(v);
        return result;
    }

bool qscriptvalue_cast_helper | ( | const QScriptValue & | value,
|  | int | type,
|  | void * | ptr
| ) |  | `[inline]`

Search for all occurrences

Definition at line 346 of file qscriptengine.h.

    {
        return QScriptEngine::convertV2(value, type, ptr);
    }

T qscriptvalue_cast | ( | const QScriptValue & | value | ) |

Search for all occurrences

Definition at line 352 of file qscriptengine.h.

    {
        T t;
        const int id = qMetaTypeId<T>();

        if (qscriptvalue_cast_helper(value, id, &t))
            return t;
        else if (value.isVariant())
            return qvariant_cast<T>(value.toVariant());

        return T();
    }

QVariant qscriptvalue_cast< QVariant > | ( | const QScriptValue & | value | ) | `[inline]`

Search for all occurrences

Definition at line 371 of file qscriptengine.h.

    {
        return value.toVariant();
    }

void qScriptRegisterMetaType_helper | ( | QScriptEngine * | eng,
|  | int | type,
|  | QScriptEngine::MarshalFunction | mf,
|  | QScriptEngine::DemarshalFunction | df,
|  | const QScriptValue & | prototype
| ) |  | `[inline]`

Search for all occurrences

Definition at line 383 of file qscriptengine.h.

    {
        eng->registerCustomType(type, mf, df, prototype);
    }

int qScriptRegisterMetaType | ( | QScriptEngine * | eng,
|  | QScriptValue(*)(QScriptEngine *, const T &t) | toScriptValue,
|  | void(*)(const QScriptValue &, T &t) | fromScriptValue,
|  | const QScriptValue & | prototype = `QScriptValue()`,
|  | T * | = `0`
| ) |  |

Search for all occurrences

Definition at line 392 of file qscriptengine.h.

    {
        const int id = qRegisterMetaType<T>(); // make sure it's registered

        qScriptRegisterMetaType_helper(
            eng, id, reinterpret_cast<QScriptEngine::MarshalFunction>(toScriptValue),
            reinterpret_cast<QScriptEngine::DemarshalFunction>(fromScriptValue),
            prototype);

        return id;
    }

QScriptValue qScriptValueFromSequence | ( | QScriptEngine * | eng,
|  | const Container & | cont
| ) |  |

Search for all occurrences

Definition at line 413 of file qscriptengine.h.

    {
        QScriptValue a = eng->newArray();
        typename Container::const_iterator begin = cont.begin();
        typename Container::const_iterator end = cont.end();
        typename Container::const_iterator it;
        quint32 i;
        for (it = begin, i = 0; it != end; ++it, ++i)
            a.setProperty(i, qScriptValueFromValue(eng, *it));
        return a;
    }

void qScriptValueToSequence | ( | const QScriptValue & | value,
|  | Container & | cont
| ) |  |

Search for all occurrences

Definition at line 426 of file qscriptengine.h.

    {
        quint32 len = value.property(QLatin1String("length")).toUInt32();
        for (quint32 i = 0; i < len; ++i) {
            QScriptValue item = value.property(i);
    #if defined Q_CC_MSVC && !defined Q_CC_MSVC_NET
            cont.push_back(qscriptvalue_cast<Container::value_type>(item));
    #else
            cont.push_back(qscriptvalue_cast<typename Container::value_type>(item));
    #endif
        }
    }

int qScriptRegisterSequenceMetaType | ( | QScriptEngine * | engine,
|  | const QScriptValue & | prototype = `QScriptValue()`,
|  | T * | = `0`
| ) |  |

Search for all occurrences

Definition at line 440 of file qscriptengine.h.

    {
        return qScriptRegisterMetaType<T>(engine, qScriptValueFromSequence,
                                          qScriptValueToSequence, prototype);
    }

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

Search for all occurrences

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

Search for all occurrences