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, QPermission::if_permission<T> = true> 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, QPermission::if_permission<T> = true> std::optional < T > QPermission:: value () const

返迴 類型化權限 類型 T ,或 std::nullopt 若此 QPermission object doesn't contain one.

使用 type () for dynamically choosing which typed permission to request.

此函數僅參與重載解析,若 T is one of the 類型化權限 類:

QBluetoothPermission

訪問藍牙外圍設備

QCalendarPermission

訪問用戶的日曆

QCameraPermission

訪問攝像頭為取得圖片 (或視頻)

QContactsPermission

訪問用戶的聯係人

QLocationPermission

訪問用戶的位置

QMicrophonePermission

為監視訪問麥剋風 (或錄製聲音)