ScriptEngine Classclass QInstaller::ScriptEngine
The ScriptEngine class is used to prepare and run the component scripts. More...
|ScriptEngine(QInstaller::PackageManagerCore *core = 0)|
|QJSValue||callScriptMethod(const QJSValue &scriptContext, const QString &methodName, const QJSValueList &arguments = QJSValueList())|
|QJSValue||evaluate(const QString &program, const QString &fileName = QString(), int lineNumber = 1)|
|QJSValue||loadInContext(const QString &context, const QString &fileName, const QString &scriptInjection = QString())|
|QJSValue||newArray(uint length = 0)|
|QJSValue||newQObject(QObject *object, bool qtScriptCompat = true)|
Member Function Documentation
ScriptEngine::ScriptEngine(QInstaller::PackageManagerCore *core = 0)
Constructs a script engine with core as parent.
void ScriptEngine::addToGlobalObject(QObject *object)
Registers QObject object in the engine, and makes it globally accessible under its object name.
QJSValue ScriptEngine::callScriptMethod(const QJSValue &scriptContext, const QString &methodName, const QJSValueList &arguments = QJSValueList())
Tries to call the method specified by methodName with the arguments specified by arguments within the script and returns the result. If the method does not exist or is not callable, an undefined result is returned. If the call to the method succeeds and the return value is still undefined, a null value will be returned instead. If the method call has an exception, its string representation is thrown as an Error exception.
Note: The method is not called if scriptContext is the same method, to avoid infinite recursion.
QJSValue ScriptEngine::evaluate(const QString &program, const QString &fileName = QString(), int lineNumber = 1)
Evaluates program, using lineNumber as the base line number, and returns the results of the evaluation. fileName is used for error reporting.
QJSValue ScriptEngine::globalObject() const
Returns a global object.
QJSValue ScriptEngine::loadInContext(const QString &context, const QString &fileName, const QString &scriptInjection = QString())
Loads a script into the given context at fileName inside the ScriptEngine.
The installer and all its components as well as other useful stuff are being exported into the script. For more information, see Component Scripting. Throws Error when either the script at fileName could not be opened, or the QScriptEngine could not evaluate the script.
TODO: document scriptInjection.
Signals and slots, properties and children of object are available as properties of the created QJSValue. If qtScriptCompat is set to
true (default), some helper methods and properties from the legacy
QtScript module are added:
- findChild(), findChildren() recursively search for child objects with the given object name.
- Direct child objects are made accessible as properties under their respective object names.
void ScriptEngine::removeFromGlobalObject(QObject *object)
Removes the object name from the global object.
© 2021 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. The Qt Company, Qt and their respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.