本页内容

QNtfsPermissionCheckGuard Class

QNtfsPermissionCheckGuard 类是一个用于管理 NTFS 权限检查的 RAII 类。更多内容...

头文件: #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()

详细说明

出于性能考虑,QFile 、QFileInfo 及相关类默认不会对 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 6.6 起,变量qt_ntfs_permission_lookup 已被废弃。

成员函数文档

QNtfsPermissionCheckGuard::QNtfsPermissionCheckGuard()

创建一个守护进程,并调用函数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 中引入。

© 2026 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.