可用于在应用程序中实现 JavaScript 脚本功能,通过绑定 JavaScript 对象与 QObjects,提供 KJSEmbed::Engine 作为运行嵌入式 JavaScript 的主接口,支持 CMake 构建并链接 KF5::JsEmbed。【此简介由AI生成】
| Files | Last commit | Last update |
|---|---|---|
| 3 years ago | ||
| 4 years ago | ||
| 4 years ago | ||
| 4 years ago | ||
| 4 years ago | ||
| 4 years ago | ||
| 4 years ago | ||
| 4 years ago | ||
| 4 years ago | ||
| 4 years ago | ||
| 4 years ago | ||
| 4 years ago | ||
| 4 years ago | ||
| 4 years ago |
KJSEmbed
Binding Javascript object to QObjects
Introduction
KSJEmbed provides a method of binding JavaScript objects to QObjects, so you can script your applications.
Usage
If you are using CMake, you need to have
find_package(KF5JsEmbed NO_MODULE)
(or similar) in your CMakeLists.txt file, and you need to link to KF5::JsEmbed.
The KJSEmbed::Engine class provides the main interface for running embedded Javascript.
KJSEmbed::Engine *engine = new KJSEmbed::Engine();
KJS::Interpreter *interpreter = engine->interpreter();
interpreter->setShouldPrintExceptions(true);
KJS::ExecState *exec = interpreter->globalExec();
KJS::UString code("print(\"Hello World\")");
KJSEmbed::Engine::ExitStatus exitstatus = engine->execute(code);
KJS::Completion completion = engine->completion();
if (exitstatus != KJSEmbed::Engine::Success) {
KJS::JSValue* value = completion.value();
qDebug() << value->toString(exec).qstring();
}