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
QHarmonyApplication Class Reference

Native interface to a core application on HarmonyOS. More...

Collaboration diagram for QHarmonyApplication:

Detailed Description

Native interface to a core application on HarmonyOS.

Accessed through QCoreApplication::nativeInterface().

On HarmonyOS, the ArkTS runtime and the platform APIs run on the main thread of the process, called the JS thread. The Qt application runs on a separate thread, called the Qt thread. This is the thread of the QCoreApplication object. This interface runs application code on the JS thread, where the code receives a QHarmonyJsContext. It also brings results back to the Qt thread.

Code that runs on the JS thread must follow these rules: \list

  • It must not wait for the Qt thread, which may itself be waiting in runOnJsThreadAndWait(). Send results back asynchronously, with runOnQtThread() or through QPromise.
  • It must not access Qt-thread objects directly, not even through a QPointer. A QPointer is created, checked, and dereferenced only on the thread of its object. The JS thread only passes copies of it along. The functor posted to the Qt thread checks the QPointer there.
  • A JS callback may run after the Qt event loop has finished. Tasks that it queues with runOnQtThread() then never run.
  • A napi_value that it obtains is valid until the task returns, and must not leave the JS thread. To keep a JS object longer, use a QHarmonyJsObjectRef.
  • Resources bound to the JS engine, such as references and listeners, must be released on the JS thread.
  • The JS thread also runs the platform UI, so tasks must be short. \endlist

Each task runs inside its own Node-API handle scope. A C++ exception that a task throws and a JS exception that it leaves pending are caught and logged on the JS thread. A task that needs to react to a failure must handle it itself.

\inmodule QtCore \inheaderfile QCoreApplication

See also
{Qt for HarmonyOS Platform API}

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