Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QPermission Class Reference

\inmodule QtCore \inheaderfile QPermissions More...

#include <qpermissions.h>

+ Collaboration diagram for QPermission:

Public Member Functions

 QPermission ()=default
 
template<typename T , if_permission< T > = true>
 QPermission (const T &t)
 
Qt::PermissionStatus status () const
 Returns the status of the permission.
 
QMetaType type () const
 Returns the type of the permission.
 
template<typename T , if_permission< T > = true>
std::optional< T > value () const
 

Friends

class QCoreApplication
 
Q_CORE_EXPORT QDebug operator<< (QDebug debug, const QPermission &)
 

Detailed Description

\inmodule QtCore \inheaderfile QPermissions

Since
6.5

An opaque wrapper of a typed permission.

The QPermission class is an opaque wrapper of a \l{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{});
Access the camera for taking pictures or videos.
#define qApp

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();
});
\inmodule QtCore \inheaderfile QPermissions
PermissionStatus

To inspect the properties of the original, typed permission, use the \l {QPermission::}{value()} function:

QLocationPermission locationPermission;
qApp->requestPermission(locationPermission, this, &LocationWidget::permissionUpdated);
Access the user's location.
Q_CORE_EXPORT void setAccuracy(Accuracy accuracy)
Sets the desired accuracy of the request.
void LocationWidget::permissionUpdated(const QPermission &permission)
{
if (permission.status() != Qt::PermissionStatus:Granted)
auto locationPermission = permission.value<QLocationPermission>();
if (!locationPermission || locationPermission->accuracy() != QLocationPermission::Precise)
return;
updatePreciseLocation();
}
std::optional< T > value() const
Qt::PermissionStatus status() const
Returns the status of the permission.

\target typed permission

Definition at line 34 of file qpermissions.h.

Constructor & Destructor Documentation

◆ QPermission() [1/2]

QPermission::QPermission ( )
explicitdefault

◆ QPermission() [2/2]

template<typename T , if_permission< T > = true>
QPermission::QPermission ( const T & t)
inline

Definition at line 45 of file qpermissions.h.

Member Function Documentation

◆ status()

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

Returns the status of the permission.

Definition at line 47 of file qpermissions.h.

◆ type()

QMetaType QPermission::type ( ) const
inline

Returns the type of the permission.

Definition at line 49 of file qpermissions.h.

References QVariant::metaType().

Referenced by nativeStringsFromPermission().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ value()

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

Definition at line 52 of file qpermissions.h.

Referenced by nativeStringsFromPermission().

+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ operator<<

Q_CORE_EXPORT QDebug operator<< ( QDebug debug,
const QPermission & permission )
friend

Definition at line 653 of file qpermissions.cpp.

◆ QCoreApplication

friend class QCoreApplication
friend

Definition at line 69 of file qpermissions.h.


The documentation for this class was generated from the following files: