QAxScript Class

QAxScript class provides a wrapper around script code. 更多...

头: #include <QAxScript>
qmake: QT += axcontainer
继承: QObject

公共类型

enum FunctionFlags { FunctionNames, FunctionSignatures }

公共函数

QAxScript (const QString & name , QAxScriptManager * manager )
~QAxScript ()
QVariant call (const QString & function , const QVariant & var1 = QVariant(), const QVariant & var2 = QVariant(), const QVariant & var3 = QVariant(), const QVariant & var4 = QVariant(), const QVariant & var5 = QVariant(), const QVariant & var6 = QVariant(), const QVariant & var7 = QVariant(), const QVariant & var8 = QVariant())
QVariant call (const QString & function , QList<QVariant> & arguments )
QStringList 函数 (FunctionFlags flags = FunctionNames) const
bool load (const QString & code , const QString & language = QString())
QString scriptCode () const
QAxScriptEngine * scriptEngine () const
QString scriptName () const

信号

void entered ()
void error (int code , const QString & description , int sourcePosition , const QString & sourceText )
void finished ()
void finished (const QVariant & result )
void finished (int code , const QString & source , const QString & description , const QString & help )
void stateChanged (int state )

额外继承成员

详细描述

QAxScript class provides a wrapper around script code.

Every instance of the QAxScript class represents a piece of scripting code in a particular scripting language. The code is loaded into the script engine using load (). Functions declared in the code can be called using call ().

The script provides scriptEngine () provides feedback to the application through signals. The most important signal is the error () signal. Direct access to the QAxScriptEngine is provided through the scriptEngine () 函数。

警告: This class is not available with the bcc5.5 compiler.

另请参阅 QAxScriptEngine , QAxScriptManager , QAxBase ,和 ActiveQt 框架 .

成员类型文档编制

enum QAxScript:: FunctionFlags

This FunctionFlags enum describes formatting for function introspection.

常量 描述
QAxScript::FunctionNames 0 Only function names are returned.
QAxScript::FunctionSignatures 1 Returns the functions with signatures.

成员函数文档编制

QAxScript:: QAxScript (const QString & name , QAxScriptManager * manager )

构造 QAxScript object called name and registers it with the QAxScriptManager manager . This is usually done by the QAxScriptManager class when loading a script .

A script should always have a name. A manager is necessary to allow the script code to reference objects in the application. The manager takes ownership of the object.

QAxScript:: ~QAxScript ()

Destroys the object, releasing all allocated resources.

QVariant QAxScript:: call (const QString & function , const QVariant & var1 = QVariant(), const QVariant & var2 = QVariant(), const QVariant & var3 = QVariant(), const QVariant & var4 = QVariant(), const QVariant & var5 = QVariant(), const QVariant & var6 = QVariant(), const QVariant & var7 = QVariant(), const QVariant & var8 = QVariant())

调用 function , passing the parameters var1 , var1 , var2 , var3 , var4 , var5 , var6 , var7 and var8 as arguments and returns the value returned by the function, or an invalid QVariant if the function does not return a value or when the function call failed.

QAxScriptManager::call () for more information about how to call script functions.

QVariant QAxScript:: call (const QString & function , QList < QVariant > & arguments )

这是重载函数。

调用 function passing arguments as parameters, and returns the result. Returns when the script's execution has finished.

QAxScriptManager::call () for more information about how to call script functions.

[signal] void QAxScript:: entered ()

This signal is emitted when a script engine has started executing code.

[signal] void QAxScript:: error ( int code , const QString & description , int sourcePosition , const QString & sourceText )

This signal is emitted when an execution error occurred while running a script.

code , description , sourcePosition and sourceText contain information about the execution error.

[signal] void QAxScript:: finished ()

This signal is emitted when a script engine has finished executing code.

注意: 信号 finished 在此类中是重载。要使用函数指针句法连接到此信号,必须在静态铸造中指定信号类型,如此范例所示:

connect(axScript, static_cast<void(QAxScript::*)()>(&QAxScript::finished),
    [=](){ /* ... */ });
					

[signal] void QAxScript:: finished (const QVariant & result )

这是重载函数。

result contains the script's result. This will be an invalid QVariant if the script has no return value.

注意: 信号 finished 在此类中是重载。要使用函数指针句法连接到此信号,必须在静态铸造中指定信号类型,如此范例所示:

connect(axScript, static_cast<void(QAxScript::*)(const QVariant &)>(&QAxScript::finished),
    [=](const QVariant &result){ /* ... */ });
					

[signal] void QAxScript:: finished ( int code , const QString & source , const QString & description , const QString & help )

这是重载函数。

code , source , description and help contain exception information when the script terminated.

注意: 信号 finished 在此类中是重载。要使用函数指针句法连接到此信号,必须在静态铸造中指定信号类型,如此范例所示:

connect(axScript, static_cast<void(QAxScript::*)(int, const QString &, const QString &, const QString &)>(&QAxScript::finished),
    [=](int code, const QString &source, const QString &description, const QString &help){ /* ... */ });
					

QStringList QAxScript:: 函数 ( FunctionFlags flags = FunctionNames) const

Returns a list of all the functions in this script if the respective script engine supports introspection; otherwise returns an empty list. The functions are either provided with full prototypes or only as names, depending on the value of flags .

另请参阅 QAxScriptEngine::hasIntrospection ().

bool QAxScript:: load (const QString & code , const QString & language = QString())

Loads the script source code written in language language into the script engine. Returns true if code was successfully entered into the script engine; otherwise returns false.

language is empty (the default) it will be determined heuristically. If code contains the string End Sub it will be interpreted as VBScript, otherwise as JScript. Additional scripting languages can be registered using QAxScriptManager::registerEngine ().

This function can only be called once for each QAxScript object, which is done automatically when using QAxScriptManager::load ().

QString QAxScript:: scriptCode () const

Returns the script's code, or the null-string if no code has been loaded yet.

另请参阅 load ().

QAxScriptEngine *QAxScript:: scriptEngine () const

Returns a pointer to the script engine.

You can use the object returned to connect signals to the script functions, or to access the script engine directly.

QString QAxScript:: scriptName () const

Returns the name of the script.

[signal] void QAxScript:: stateChanged ( int state )

This signal is emitted when a script engine changes state. state can be any value in the QAxScriptEngine::State 枚举。