QPermission 类

类型化权限的不透明包裹器。 更多...

头: #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

详细描述

QPermission 类是不透明包裹器为 类型化权限 ,当校验 (或请求) 权限时使用。不需要明确构造此类型,因为在校验 (或请求) 权限时会自动使用类型:

qApp->checkPermission(QCameraPermission{});
					

当请求权限时,给定函子将传递 QPermission 实例,可以用于校验请求结果:

qApp->requestPermission(QCameraPermission{}, [](const QPermission &permission) {
    if (permission.status() == Qt::PermissionStatus:Granted)
        takePhoto();
});
					

要审查原始类型化权限的特性,使用 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();
}
					

类型化权限

下列权限是可用的:

QBluetoothPermission 访问蓝牙外围设备
QCalendarPermission 访问用户的日历
QCameraPermission 访问摄像头为取得图片 (或视频)
QContactsPermission 访问用户的联系人
QLocationPermission 访问用户的位置
QMicrophonePermission 为监视访问麦克风 (或录制声音)

另请参阅 应用程序权限 .

成员函数文档编制

template <typename T, if_permission<T>> QPermission:: QPermission (const T & type )

构造权限从给定 类型化权限 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 类型化权限 类:

QBluetoothPermission 访问蓝牙外围设备
QCalendarPermission 访问用户的日历
QCameraPermission 访问摄像头为取得图片 (或视频)
QContactsPermission 访问用户的联系人
QLocationPermission 访问用户的位置
QMicrophonePermission 为监视访问麦克风 (或录制声音)

Qt::PermissionStatus QPermission:: status () const

返回权限的状态。

QMetaType QPermission:: type () const

Returns the type of the permission.

template <typename T, if_permission<T>> std::optional < T > QPermission:: value () const

返回 类型化权限 类型 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 类型化权限 类:

QBluetoothPermission 访问蓝牙外围设备
QCalendarPermission 访问用户的日历
QCameraPermission 访问摄像头为取得图片 (或视频)
QContactsPermission 访问用户的联系人
QLocationPermission 访问用户的位置
QMicrophonePermission 为监视访问麦克风 (或录制声音)