Jump to content

Qt for HarmonyOS/qtohosextras doc/Serial Port Permissions Example

From Qt Wiki
Revision as of 09:10, 16 September 2026 by Shawn Luo (talk | contribs) (Add example documentation from qdoc output (QTFOROH-2307))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

< Qt for HarmonyOS / qtohosextras doc

Serial Port Permissions Example

Demonstrates requesting and checking OHOS serial port access rights.


The window lists the serial ports found with QSerialPortInfo::availablePorts(). For each port, one button requests access with QOhosAppContext::requestSerialPortAccessRightIfNeeded() and another checks it synchronously with QOhosAppContext::hasSerialPortAccessRight(). The asynchronous result arrives through the QOhosAppContext::serialPortAccessRightResponseReceived() signal, which delivers a context object when access was granted. The example stores the context in a dedicated window whose closing releases it.

Note: The lifetime of the permission is strictly tied to the delivered context object: the caller must keep the QSharedPointer alive for as long as access is required, and releasing the last reference revokes the permission.

Files: