⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qscriptengine.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
{    Q_D(const QScriptEngine);    return d->uncaughtExceptionBacktrace();}/*!  Returns the default prototype associated with the given \a metaTypeId,  or an invalid QScriptValue if no default prototype has been set.  \sa setDefaultPrototype()*/QScriptValue QScriptEngine::defaultPrototype(int metaTypeId) const{    Q_D(const QScriptEngine);    return d->defaultPrototype(metaTypeId);}/*!  Sets the default prototype of the given \a metaTypeId to \a prototype.  The default prototype provides a script interface for values of  type \a 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 \a metaTypeId, the default  prototype will be set as the QScriptValue's prototype.  \sa defaultPrototype(), qScriptRegisterMetaType(), QScriptable, {Default Prototypes Example}*/void QScriptEngine::setDefaultPrototype(int metaTypeId, const QScriptValue &prototype){    Q_D(QScriptEngine);    d->setDefaultPrototype(metaTypeId, QScriptValuePrivate::valueOf(prototype));}/*!    \typedef QScriptEngine::FunctionSignature    \relates QScriptEngine    The function signature \c{QScriptValue f(QScriptContext *, QScriptEngine *)}.    A function with such a signature can be passed to QScriptEngine::newFunction()    to wrap the function.*//*!    \typedef QScriptEngine::MarshalFunction    \internal*//*!    \typedef QScriptEngine::DemarshalFunction    \internal*//*!    \internal*/QScriptValue QScriptEngine::create(int type, const void *ptr){    Q_D(QScriptEngine);    return d->create(type, ptr);}/*!    \internal*/bool QScriptEngine::convert(const QScriptValue &value, int type, void *ptr){    Q_D(QScriptEngine);    return d->convert(QScriptValuePrivate::valueOf(value), type, ptr);}/*!    \internal*/void QScriptEngine::registerCustomType(int type, MarshalFunction mf,                                       DemarshalFunction df,                                       const QScriptValue &prototype){    Q_D(QScriptEngine);    QScriptCustomTypeInfo info = d->m_customTypes.value(type);    info.marshal = mf;    info.demarshal = df;    info.prototype = QScriptValuePrivate::valueOf(prototype);    d->m_customTypes.insert(type, info);}/*!    Imports the given \a 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 \c{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().    \sa QScriptExtensionPlugin, {Creating QtScript Extensions}*/QScriptValue QScriptEngine::importExtension(const QString &extension){    Q_D(QScriptEngine);    return d->importExtension(extension);}/*! \fn QScriptValue QScriptEngine::toScriptValue(const T &value)    Creates a QScriptValue with the given \a value.    Note that the template type \c{T} must be known to QMetaType.    See \l{Conversion Between QtScript and C++ Types} for a    description of the built-in type conversion provided by    QtScript. By default, the types that are not specially handled by    QtScript are represented as QVariants (e.g. the \a value is passed    to newVariant()); you can change this behavior by installing your    own type conversion functions with qScriptRegisterMetaType().    \warning This function is not available with MSVC 6. Use    qScriptValueFromValue() instead if you need to support that    version of the compiler.    \sa fromScriptValue(), qScriptRegisterMetaType()*//*! \fn T QScriptEngine::fromScriptValue(const QScriptValue &value)    Returns the given \a value converted to the template type \c{T}.    Note that \c{T} must be known to QMetaType.    See \l{Conversion Between QtScript and C++ Types} for a    description of the built-in type conversion provided by    QtScript.    \warning This function is not available with MSVC 6. Use    qScriptValueToValue() or qscriptvalue_cast() instead if you need    to support that version of the compiler.    \sa toScriptValue(), qScriptRegisterMetaType()*//*!    \fn QScriptValue qScriptValueFromValue(QScriptEngine *engine, const T &value)    \since 4.3    \relates QScriptEngine    Creates a QScriptValue using the given \a engine with the given \a    value of template type \c{T}.    This function is equivalent to QScriptEngine::toScriptValue().    It is provided as a work-around for MSVC 6, which doesn't support    member template functions.    \sa qScriptValueToValue()*//*!    \fn T qScriptValueToValue(const QScriptValue &value)    \since 4.3    \relates QScriptEngine    Returns the given \a value converted to the template type \c{T}.    This function is equivalent to QScriptEngine::fromScriptValue().    It is provided as a work-around for MSVC 6, which doesn't    support member template functions.    \sa qScriptValueFromValue()*//*!    \fn QScriptValue qScriptValueFromSequence(QScriptEngine *engine, const Container &container)    \since 4.3    \relates QScriptEngine    Creates an array in the form of a QScriptValue using the given \a engine    with the given \a container of template type \c{Container}.    The \c Container type must provide a \c const_iterator class to enable the    contents of the container to be copied into the array.    Additionally, the type of each element in the sequence should be suitable    for conversion to a QScriptValue.    See \l{QtScript Module#Conversion Between QtScript and C++ Types}    {Conversion Between QtScript and C++ Types} for more information about the    restrictions on types that can be used with QScriptValue.    \sa qScriptValueFromValue()*//*!    \fn void qScriptValueToSequence(const QScriptValue &value, Container &container)    \since 4.3    \relates QScriptEngine    Copies the elements in the sequence specified by \a value to the given    \a container of template type \c{Container}.    The \a value used is typically an array, but any container can be copied    as long as it provides a \c length property describing how many elements    it contains.    Additionally, the type of each element in the sequence must be suitable    for conversion to a C++ type from a QScriptValue.    See \l{QtScript Module#Conversion Between QtScript and C++ Types}    {Conversion Between QtScript and C++ Types} for more information about the    restrictions on types that can be used with QScriptValue.    \sa qscriptvalue_cast()*//*!    \fn T qscriptvalue_cast(const QScriptValue &value)    \since 4.3    \relates QScriptValue    Returns the given \a value converted to the template type \c{T}.    \sa qScriptRegisterMetaType(), QScriptEngine::toScriptValue()*//*! \fn int qScriptRegisterMetaType(            QScriptEngine *engine,            QScriptValue (*toScriptValue)(QScriptEngine *, const T &t),            void (*fromScriptValue)(const QScriptValue &, T &t),            const QScriptValue &prototype = QScriptValue())    \relates QScriptEngine    Registers the type \c{T} in the given \a engine. \a toScriptValue must    be a function that will convert from a value of type \c{T} to a    QScriptValue, and \a fromScriptValue a function that does the    opposite. \a prototype, if valid, is the prototype that's set on    QScriptValues returned by \a toScriptValue.    Returns the internal ID used by QMetaType.    You only need to call this function if you want to provide custom    conversion of values of type \c{T}, i.e. if the default    QVariant-based representation and conversion is not    appropriate. If you only want to define a common script interface    for values of type \c{T}, and don't care how those values are    represented, use    \l{QScriptEngine::setDefaultPrototype()}{setDefaultPrototype}()    instead.    You need to declare the custom type first with    Q_DECLARE_METATYPE().    After a type has been registered, you can convert from a    QScriptValue to that type using    \l{QScriptEngine::fromScriptValue()}{fromScriptValue}(), and    create a QScriptValue from a value of that type using    \l{QScriptEngine::toScriptValue()}{toScriptValue}(). The engine    will take care of calling the proper conversion function when    calling C++ slots, and when getting or setting a C++ property;    i.e. the custom type may be used seamlessly on both the C++ side    and the script side.    The following is an example of how to use this function. We will    specify custom conversion of our type \c{MyStruct}. Here's the C++    type:    \code      struct MyStruct {        int x;        int y;      };    \endcode    We must declare it so that the type will be known to QMetaType:    \code      Q_DECLARE_METATYPE(MyStruct)    \endcode    Next, the \c{MyStruct} conversion functions. We represent the    \c{MyStruct} value as a script object and just copy the properties:    \code    QScriptValue toScriptValue(QScriptEngine *engine, const MyStruct &s)    {      QScriptValue obj = engine->newObject();      obj.setProperty("x", QScriptValue(engine, s.x));      obj.setProperty("y", QScriptValue(engine, s.y));      return obj;    }    void fromScriptValue(const QScriptValue &obj, MyStruct &s)    {      s.x = obj.property("x").toInt32();      s.y = obj.property("y").toInt32();    }    \endcode    Now we can register \c{MyStruct} with the engine:    \code    qScriptRegisterMetaType(engine, toScriptValue, fromScriptValue);    \endcode    Working with \c{MyStruct} values is now easy:    \code    MyStruct s = qscriptvalue_cast<MyStruct>(context->argument(0));    ...    MyStruct s2;    s2.x = s.x + 10;    s2.y = s.y + 20;    QScriptValue v = engine->toScriptValue(s2);    \endcode    If you want to be able to construct values of your custom type    from script code, you have to register a constructor function for    the type. For example:    \code    QScriptValue createMyStruct(QScriptContext *, QScriptEngine *engine)    {        MyStruct s;        s.x = 123;        s.y = 456;        return engine->toScriptValue(s);    }    ...    QScriptValue ctor = engine.newFunction(createMyStruct);    engine.globalObject().setProperty("MyStruct", ctor);    \endcode    \sa qScriptRegisterSequenceMetaType(), qRegisterMetaType()*//*!    \macro Q_SCRIPT_DECLARE_QMETAOBJECT(QMetaObject, ArgType)    \since 4.3    \relates QScriptEngine    Declares the given \a QMetaObject. Used in combination with    QScriptEngine::scriptValueFromQMetaObject() to make enums and    instantiation of \a QMetaObject available to script code. The    constructor generated by this macro takes a single argument of    type \a ArgType; typically the argument is the parent type of the    new instance, in which case \a ArgType is \c{QWidget*} or    \c{QObject*}. Objects created by the constructor will have    QScriptEngine::AutoOwnership ownership.*//*! \fn int qScriptRegisterSequenceMetaType(            QScriptEngine *engine,            const QScriptValue &prototype = QScriptValue())    \relates QScriptEngine    Registers the sequence type \c{T} in the given \a engine. This    function provides conversion functions that convert between \c{T}    and Qt Script \c{Array} objects. \c{T} must provide a    const_iterator class and begin(), end() and push_back()    functions. If \a prototype is valid, it will be set as the    prototype of \c{Array} objects due to conversion from \c{T};    otherwise, the standard \c{Array} prototype will be used.    Returns the internal ID used by QMetaType.    You need to declare the container type first with    Q_DECLARE_METATYPE(). Example:    \code    Q_DECLARE_METATYPE(QVector<int>)    ...    qScriptRegisterSequenceMetaType<QVector<int> >(engine);    ...    QVector<int> v = qscriptvalue_cast<QVector<int> >(engine->evaluate("[5, 1, 3, 2]"));    qSort(v.begin(), v.end());    QScriptValue a = engine->toScriptValue(v);    qDebug() << a.toString(); // outputs "[1, 2, 3, 5]"    \endcode    \sa qScriptRegisterMetaType()*//*!  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.*/void QScriptEngine::collectGarbage(){    Q_D(QScriptEngine);    d->gc();}/*!  Sets the interval between calls to QCoreApplication::processEvents  to \a 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.  \sa processEventsInterval()*/void QScriptEngine::setProcessEventsInterval(int interval){    Q_D(QScriptEngine);    d->m_processEventsInterval = interval;}/*!  Returns the interval in milliseconds between calls to  QCoreApplication::processEvents() while the interpreter is running.  \sa setProcessEventsInterval()*/int QScriptEngine::processEventsInterval() const{    Q_D(const QScriptEngine);    return d->m_processEventsInterval;}#endif // QT_NO_SCRIPT

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -