IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QPermission Class

An opaque wrapper of a typed permission.

This class was introduced in Qt 6.5.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QPermission Class▲

  • Header: QPermissions

  • Since: Qt 6.5

  • CMake:

    find_package(Qt6 REQUIRED COMPONENTS Core)

    target_link_libraries(mytarget PRIVATE Qt6::Core)

  • qmake: QT += core

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:

 
Sélectionnez
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:

 
Sélectionnez
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:

 
Sélectionnez
QLocationPermission locationPermission;
locationPermission.setAccuracy(QLocationPermission::Precise);
qApp->requestPermission(locationPermission, this, &LocationWidget::permissionUpdated);
 
Sélectionnez
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:

See Also▲

Member Function Documentation▲

 

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.

This constructor participates in overload resolution only if T is one of the typed permission classes:

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

Returns the status of the permission.

QMetaType QPermission::type() const▲

Returns the type of the permission.

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.

This function participates in overload resolution only if T is one of the typed permission classes:

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+