ohos: fix where runOnJsThread() destroys its task


QHarmonyApplication::runOnJsThread() documents that the task, with
everything it captures, is destroyed on the JS thread, but a copy of
the task can be destroyed on the calling thread.

QOhosJsThreadGateway::invoke() destroys a queued task on the JS thread,
but runOnJsThread() moves its by-value parameter into the closure it
queues, and a copy can stay behind in the parameter. The standard
leaves a moved-from std::function in a valid but unspecified state, and
the libc++ in the OHOS SDK keeps a copy of a small task, such as a
lambda capturing a single shared_ptr, in the moved-from object. That
copy is destroyed on the calling thread when runOnJsThread() returns.
If the JS thread has already run the task and destroyed its own copy,
the leftover holds the last reference to the captured state and
releases it on the wrong thread. A caller that keeps the task in its
own std::function and passes it with std::move() has the same leftover
one level up, in its own object.

Take the task by rvalue reference and hand it to
QtOhos::takeFunctionToSharedPtr(), which moves it into a shared_ptr and
leaves the caller's std::function empty. The JS thread takes the task
out of the shared_ptr before running it, so the task is destroyed there
even if a copy of the shared_ptr outlives it. Take the runOnQtThread()
task by rvalue reference too, so that forwarding it to
QtOhos::invokeInQtThread() empties the caller's std::function as well.

This changes the signature of two public functions. They were merged
in October 2026 and are not part of any release yet, and the
HarmonyOS platform API is documented as being in Technology Preview
and subject to change. The change cannot break code silently: passing
a std::function lvalue to either function no longer compiles, and the
caller has to move it or copy it explicitly.

Task-number: QTBUG-151347
Pick-to: 6.12
Change-Id: Ib08370c829fd5aa1b56bccc0da788ee3aa926edf
Reviewed-by: SanthoshKumar Selvaraj <santhosh.kumar.selvaraj@qt.io>
commitddd7d91c22ed770784b71183b5addab7087eab61
parent903313b92e52231650bc6132233fcc3178473c2f
authorZbigniew Chyla <zbigniew.chyla@qt.io>
committerZbigniew Chyla <zbigniew.chyla@qt.io>
commit timeTue, 20 Oct 2026 10:41:22 +0000