QNtfsPermissionCheckGuard Class

QNtfsPermissionCheckGuard 类是一个 RAII 类,用于管理 NTFS 权限检查。更多

头文件: #include <QNtfsPermissionCheckGuard>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
Qt 6.6

公共函数

(since 6.6) bool qAreNtfsPermissionChecksEnabled()
(since 6.6) bool qDisableNtfsPermissionChecks()
(since 6.6) bool qEnableNtfsPermissionChecks()

详细说明

出于性能考虑,QFileQFileInfo 及相关类默认不对 NTFS 文件系统执行完整的所有权和权限(ACL)检查。在该类任何实例的生命周期内,该默认值会被覆盖并执行高级检查。这为管理启用和禁用对默认行为的更改提供了一种安全、简便的方法。

举例说明

void complexFunction()
{
    QNtfsPermissionCheckGuard permissionGuard;  // check is enabled

    // do complex things here that need permission check enabled

}   // as the guard goes out of scope the check is disabled

该类仅适用于 Windows。

qt_ntfs_permission_lookup

在 Qt 6.6 之前,用户必须直接操作全局变量qt_ntfs_permission_lookup 。然而,这是一个非原子全局变量,因此容易出现数据竞赛。

因此,自 Qt XML 6.6 起,该变量qt_ntfs_permission_lookup 已被弃用。

成员函数文档

QNtfsPermissionCheckGuard::QNtfsPermissionCheckGuard()

创建一个 guard 并调用函数qEnableNtfsPermissionChecks().

[noexcept] QNtfsPermissionCheckGuard::~QNtfsPermissionCheckGuard()

销毁保护并调用函数qDisableNtfsPermissionChecks().

相关非会员

[noexcept, since 6.6] bool qAreNtfsPermissionChecksEnabled()

检查 NTFS 文件系统的权限检查状态。如果检查已启用,则返回true

该函数仅适用于 Windows 系统,因此直接操作qt_ntfs_permission_lookup 已过时。

注意: 只要qt_ntfs_permission_lookup 没有并发更新,该函数的线程安全性就有效。

注:此函数是线程安全的

此函数在 Qt 6.6 中引入。

[noexcept, since 6.6] bool qDisableNtfsPermissionChecks()

禁用 NTFS 文件系统的权限检查。如果检查被禁用,即不再有用户,则返回true

该函数仅适用于 Windows 系统,直接操作qt_ntfs_permission_lookup 已过时。

这是一个低级函数,必须(仅)调用该函数来匹配之前对qEnableNtfsPermissionChecks() 的调用。请考虑使用 RAII 类QNtfsPermissionCheckGuard

注意: 只有当qt_ntfs_permission_lookup 没有并发更新时,该函数的线程安全才有效。

注:此函数是线程安全的

此函数在 Qt 6.6 中引入。

[noexcept, since 6.6] bool qEnableNtfsPermissionChecks()

启用 NTFS 文件系统的权限检查。如果在调用此函数前已启用检查,即存在其他用户,则返回true

该函数仅适用于 Windows 系统,它使直接操作qt_ntfs_permission_lookup 变得过时。

这是一个低级函数,请考虑使用 RAII 类QNtfsPermissionCheckGuard

注意: 只要qt_ntfs_permission_lookup 没有并发更新,该函数的线程安全就有效。

注:此函数是线程安全的

此函数在 Qt 6.6 中引入。

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.