- Qt 6.11
- Qt Core
- C++ Classes
- QPermission
- Qt 6.11.1 Reference Documentation

# QPermission Class

An opaque wrapper of a typed permission. More...

Header: | `#include <QPermissions>`
CMake: | `find_package(Qt6 REQUIRED COMPONENTS Core)` `target_link_libraries(mytarget PRIVATE Qt6::Core)`
qmake: | `QT += core`
Since: | Qt 6.5

- List of all members, including inherited members

## Public Functions

| QPermission(const T &type)
Qt::PermissionStatus | status() const
QMetaType | type() const
std::optional<T> | value() const

## Detailed Description

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() function:

     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();
     }

#### Typed Permissions

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

See also Application Permissions.

## Member Function Documentation

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

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.

#### Constraints

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

### Qt::PermissionStatus QPermission::status() const

Returns the status of the permission.

### QMetaType QPermission::type() const

Returns the type of the permission.

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

Returns the typed permission of type `T`, or `std::nullopt` if this QPermission object doesn't contain one.

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

#### Constraints

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