An opaque wrapper of a typed permission. 更多...
| 头: | #include <QPermissions> |
| CMake: |
find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core) |
| qmake: | QT += core |
| Since: | Qt 6.5 |
| QPermission (const T & type ) | |
| Qt::PermissionStatus | status () const |
| QMetaType | type () const |
| std::optional<T> | value () const |
The QPermission class is an opaque wrapper of a typed permission , used when checking or requesting permissions. You do not need to construct this type explicitly, as the type is automatically used when checking or requesting permissions:
qApp->checkPermission(QCameraPermission{});
When requesting permissions, the given functor will be passed an instance of a QPermission, which can be used to check the result of the request:
qApp->requestPermission(QCameraPermission{}, [](const QPermission &permission) { if (permission.status() == Qt::PermissionStatus:Granted) takePhoto(); });
To inspect the properties of the original, typed permission, use the value () 函数:
QLocationPermission locationPermission; locationPermission.setAccuracy(QLocationPermission::Precise); qApp->requestPermission(locationPermission, this, &LocationWidget::permissionUpdated);
void LocationWidget::permissionUpdated(const QPermission &permission) { if (permission.status() != Qt::PermissionStatus:Granted) return; auto locationPermission = permission.value<QLocationPermission>(); if (!locationPermission || locationPermission->accuracy() != QLocationPermission::Precise) return; updatePreciseLocation(); }
The following permissions are available:
| QBluetoothPermission | Access Bluetooth peripherals |
| QCalendarPermission | Access the user's calendar |
| QCameraPermission | Access the camera for taking pictures or videos |
| QContactsPermission | Access the user's contacts |
| QLocationPermission | Access the user's location |
| QMicrophonePermission | Access the microphone for monitoring or recording sound |
另请参阅 Application Permissions .
Constructs a permission from the given typed permission type .
You do not need to construct this type explicitly, as the type is automatically used when checking or requesting permissions.
This constructor participates in overload resolution only if
T
is one of the
typed permission
classes:
| QBluetoothPermission | Access Bluetooth peripherals |
| QCalendarPermission | Access the user's calendar |
| QCameraPermission | Access the camera for taking pictures or videos |
| QContactsPermission | Access the user's contacts |
| QLocationPermission | Access the user's location |
| QMicrophonePermission | Access the microphone for monitoring or recording sound |
Returns the status of the permission.
Returns the type of the permission.
返回
typed permission
类型
T
,或
std::nullopt
若此
QPermission
object doesn't contain one.
使用 type () for dynamically choosing which typed permission to request.
This function participates in overload resolution only if
T
is one of the
typed permission
classes:
| QBluetoothPermission | Access Bluetooth peripherals |
| QCalendarPermission | Access the user's calendar |
| QCameraPermission | Access the camera for taking pictures or videos |
| QContactsPermission | Access the user's contacts |
| QLocationPermission | Access the user's location |
| QMicrophonePermission | Access the microphone for monitoring or recording sound |