Qt for HarmonyOS/qtohosextras doc/Serial Port Permissions Example
< 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: