QHarmonyJsObjectRef Class
The QHarmonyJsObjectRef class keeps a JS object of a HarmonyOS application alive and lets other threads hold a reference to it. More...
| Header: | #include <QHarmonyJsObjectRef> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Core)target_link_libraries(mytarget PRIVATE Qt6::Core) |
| qmake: | QT += core |
Note: All functions in this class are reentrant.
Public Functions
| QHarmonyJsObjectRef() | |
| QHarmonyJsObjectRef(const QHarmonyJsObjectRef &other) | |
| QHarmonyJsObjectRef(QHarmonyJsObjectRef &&other) | |
| ~QHarmonyJsObjectRef() | |
| bool | isNull() const |
| int | value(QHarmonyJsContext &jsContext) const |
| QHarmonyJsObjectRef & | operator=(QHarmonyJsObjectRef &&other) |
| QHarmonyJsObjectRef & | operator=(const QHarmonyJsObjectRef &other) |
Static Public Members
| QHarmonyJsObjectRef | fromValue(QHarmonyJsContext &jsContext, int value) |
Related Non-Members
| size_t | qHash(const QHarmonyJsObjectRef &key, size_t seed = 0) |
| bool | operator!=(const QHarmonyJsObjectRef &lhs, const QHarmonyJsObjectRef &rhs) |
| bool | operator==(const QHarmonyJsObjectRef &lhs, const QHarmonyJsObjectRef &rhs) |
Detailed Description
A napi_value is valid only on the JS thread, and only until the task or callback that obtained it returns. A QHarmonyJsObjectRef holds a strong reference to the object instead. You can copy, store, and compare it on any thread. On the JS thread, value() returns the object again.
The reference is released when the last copy is destroyed, on whichever thread that happens. The release itself runs asynchronously on the JS thread, so the JS object may outlive the last copy for a short time.
Two references compare equal when they refer to the same JS object, even if they were created independently.
See also Qt for HarmonyOS Platform API.
Member Function Documentation
QHarmonyJsObjectRef::QHarmonyJsObjectRef()
Constructs a null reference.
QHarmonyJsObjectRef::QHarmonyJsObjectRef(const QHarmonyJsObjectRef &other)
Constructs a copy of other, which refers to the same JS object.
[noexcept] QHarmonyJsObjectRef::QHarmonyJsObjectRef(QHarmonyJsObjectRef &&other)
Move-constructs a reference from other. other becomes a null reference.
[noexcept] QHarmonyJsObjectRef::~QHarmonyJsObjectRef()
Destroys the reference. If this is the last copy, the JS object is released asynchronously on the JS thread.
[static] QHarmonyJsObjectRef QHarmonyJsObjectRef::fromValue(QHarmonyJsContext &jsContext, int value)
Returns a reference to the JS object value, obtained in jsContext on the JS thread. Returns a null reference if value is not a JS object, that is, if it is nullptr, JS null, undefined, or a primitive. Also returns a null reference if creating the reference fails. In that case, the error is logged and no exception is left pending.
bool QHarmonyJsObjectRef::isNull() const
Returns true if this reference does not refer to any JS object. You can call this function on any thread.
int QHarmonyJsObjectRef::value(QHarmonyJsContext &jsContext) const
Returns the referenced JS object for use in jsContext on the JS thread, or nullptr for a null reference. The returned value is valid until the current task or callback returns.
[noexcept] QHarmonyJsObjectRef &QHarmonyJsObjectRef::operator=(QHarmonyJsObjectRef &&other)
Move-assigns other to this reference. other becomes a null reference.
QHarmonyJsObjectRef &QHarmonyJsObjectRef::operator=(const QHarmonyJsObjectRef &other)
Assigns other to this reference. This reference then refers to the same JS object as other.
Related Non-Members
[noexcept] size_t qHash(const QHarmonyJsObjectRef &key, size_t seed = 0)
Returns the hash value for key, using seed to seed the calculation. References that compare equal have the same hash value. You can call this function on any thread.
[noexcept] bool operator!=(const QHarmonyJsObjectRef &lhs, const QHarmonyJsObjectRef &rhs)
[noexcept] bool operator==(const QHarmonyJsObjectRef &lhs, const QHarmonyJsObjectRef &rhs)
Returns whether lhs and rhs refer to the same JS object. Two null references are equal. You can call these operators on any thread.
© 2026 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. Qt and 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.