Qt for HarmonyOS/qtohosextras doc/Want FDs Sender Example: Difference between revisions
Add example documentation from qdoc output (QTFOROH-2307) |
No edit summary |
||
| (4 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
= Want FDs Sender Example = | = Want FDs Sender Example = | ||
| Line 8: | Line 6: | ||
The form collects the target bundle, module and ability names and a set of files chosen through a file dialog. '''Send FD''' opens every file, stores its handle in QOhosWant::fds under the keys <code>keyFd0</code>, <code>keyFd1</code> and so on, logs the <code>dev</code> / <code>ino</code> numbers for cross-checking on the receiver side, and starts the target with QtOhosExtras::startAbility(). | The form collects the target bundle, module and ability names and a set of files chosen through a file dialog. '''Send FD''' opens every file, stores its handle in QOhosWant::fds under the keys <code>keyFd0</code>, <code>keyFd1</code> and so on, logs the <code>dev</code> / <code>ino</code> numbers for cross-checking on the receiver side, and starts the target with QtOhosExtras::startAbility(). | ||
The want is filled with the target names: | |||
<syntaxhighlight lang="cpp"> | |||
QtOhosExtras::QOhosWant want; | |||
want.bundleName = bundleName; | |||
want.moduleName = m_moduleNameEdit->text().trimmed(); | |||
want.abilityName = abilityName; | |||
</syntaxhighlight> | |||
Each open file descriptor is stored under its own key: | |||
<syntaxhighlight lang="cpp"> | |||
const QString fdKey = QStringLiteral("keyFd%1").arg(openedCount); | |||
want.fds.insert(fdKey, fd); | |||
</syntaxhighlight> | |||
Finally the target ability is started with the want: | |||
<syntaxhighlight lang="cpp"> | |||
const auto operationStatus = QtOhosExtras::startAbility(want); | |||
appendLog(QStringLiteral("startAbility: success=%1").arg(!operationStatus.isNull() && operationStatus->success())); | |||
</syntaxhighlight> | |||
'''Note: '''The descriptors must still be open when startAbility() is called, so the [https://doc.qt.io/qt-5/qfile.html QFile] objects are kept alive for the duration of the call. Use application-specific keys and do not reuse a key in both QOhosWant::fds and QOhosWant::parameters. | '''Note: '''The descriptors must still be open when startAbility() is called, so the [https://doc.qt.io/qt-5/qfile.html QFile] objects are kept alive for the duration of the call. Use application-specific keys and do not reuse a key in both QOhosWant::fds and QOhosWant::parameters. | ||
| Line 13: | Line 40: | ||
Files: | Files: | ||
* [[Qt_for_HarmonyOS/qtohosextras_doc/ | * [[Qt_for_HarmonyOS/qtohosextras_doc/Want_FDs_Sender_Example_-_main.cpp|abilitycontext/wantfdssender/main.cpp]] | ||
* [[Qt_for_HarmonyOS/qtohosextras_doc/ | * [[Qt_for_HarmonyOS/qtohosextras_doc/Want_FDs_Sender_Example_-_wantfdssender.pro|abilitycontext/wantfdssender/wantfdssender.pro]] | ||
[[Category:Qt for HarmonyOS]] | [[Category:Qt for HarmonyOS]] | ||
Latest revision as of 07:55, 17 September 2026
Want FDs Sender Example
Demonstrates sending open file descriptors to another ability through a want.
The form collects the target bundle, module and ability names and a set of files chosen through a file dialog. Send FD opens every file, stores its handle in QOhosWant::fds under the keys keyFd0, keyFd1 and so on, logs the dev / ino numbers for cross-checking on the receiver side, and starts the target with QtOhosExtras::startAbility().
The want is filled with the target names:
QtOhosExtras::QOhosWant want;
want.bundleName = bundleName;
want.moduleName = m_moduleNameEdit->text().trimmed();
want.abilityName = abilityName;
Each open file descriptor is stored under its own key:
const QString fdKey = QStringLiteral("keyFd%1").arg(openedCount);
want.fds.insert(fdKey, fd);
Finally the target ability is started with the want:
const auto operationStatus = QtOhosExtras::startAbility(want);
appendLog(QStringLiteral("startAbility: success=%1").arg(!operationStatus.isNull() && operationStatus->success()));
Note: The descriptors must still be open when startAbility() is called, so the QFile objects are kept alive for the duration of the call. Use application-specific keys and do not reuse a key in both QOhosWant::fds and QOhosWant::parameters.
Files: