類型化權限的不透明包裹器。 更多...
| 頭: |
#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(); }
下列權限是可用的:
| 訪問藍牙外圍設備 | |
| 訪問用戶的日曆 | |
| 訪問攝像頭為取得圖片 (或視頻) | |
| 訪問用戶的聯係人 | |
| 訪問用戶的位置 | |
| 為監視訪問麥剋風 (或錄製聲音) |
另請參閱 應用程序權限 .
構造權限從給定 類型化權限 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
類型化權限
類:
| 訪問藍牙外圍設備 | |
| 訪問用戶的日曆 | |
| 訪問攝像頭為取得圖片 (或視頻) | |
| 訪問用戶的聯係人 | |
| 訪問用戶的位置 | |
| 為監視訪問麥剋風 (或錄製聲音) |
返迴權限的狀態。
Returns the type of the permission.
返迴
類型化權限
類型
T
,或
std::nullopt
若此
QPermission
object doesn't contain one.
使用 type () for dynamically choosing which typed permission to request.
此函數僅參與重載解析,若
T
is one of the
類型化權限
類:
| 訪問藍牙外圍設備 | |
| 訪問用戶的日曆 | |
| 訪問攝像頭為取得圖片 (或視頻) | |
| 訪問用戶的聯係人 | |
| 訪問用戶的位置 | |
| 為監視訪問麥剋風 (或錄製聲音) |