Qt for HarmonyOS/qtohosextras doc/Serial Port Permissions Example: Difference between revisions
Add example documentation from qdoc output (QTFOROH-2307) |
Fix example page conversion (QTFOROH-2307) |
||
| Line 11: | Line 11: | ||
'''Note: '''The lifetime of the permission is strictly tied to the delivered context object: the caller must keep the [https://doc.qt.io/qt-5/qsharedpointer.html QSharedPointer] alive for as long as access is required, and releasing the last reference revokes the permission. | '''Note: '''The lifetime of the permission is strictly tied to the delivered context object: the caller must keep the [https://doc.qt.io/qt-5/qsharedpointer.html QSharedPointer] alive for as long as access is required, and releasing the last reference revokes the permission. | ||
* [[Qt_for_HarmonyOS/qtohosextras_doc/Serial_Port_Permissions_Example|serialportpermissions/serialportpermissions.pro]] | * [[Qt_for_HarmonyOS/qtohosextras_doc/Serial_Port_Permissions_Example|serialportpermissions/serialportpermissions.pro]] | ||
[[Category:Qt for HarmonyOS]] | [[Category:Qt for HarmonyOS]] | ||
Revision as of 09:26, 16 September 2026
< 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.