Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QHarmonyJsContext Class Reference

\inmodule QtCore More...

Collaboration diagram for QHarmonyJsContext:

Detailed Description

\inmodule QtCore

The QHarmonyJsContext class gives code on the JS thread of a HarmonyOS application access to the JS runtime.

On HarmonyOS, Qt runs the application on its own thread. The ArkTS runtime and the platform UI run on the main thread of the process, called the JS thread. Platform APIs are only available on the JS thread. To run code there, use QNativeInterface::QHarmonyApplication::runOnJsThread(). The code receives a QHarmonyJsContext as the task argument. JS callbacks created with napi_create_function() receive only a napi_env. They get the context with fromEnv().

QHarmonyAppJsContext provides the state of the application in the runtime, such as its default UIAbility instance. To get it, call QHarmonyAppJsContext::fromJsContext().

All member functions must be called on the JS thread. A napi_value that they return is valid until the task or callback that obtained it returns. It must not be passed to another thread. To keep a JS object longer, use a QHarmonyJsObjectRef.

A QHarmonyJsContext reference is valid as long as the napi_env of the context, which is until the task or callback that received or obtained it returns. Get the context again in each task or callback.

See also
{Qt for HarmonyOS Platform API}

The documentation for this class was generated from the following file: