gpt4 book ai didi

Qt set Permissions 不设置权限

转载 作者:行者123 更新时间:2023-12-01 14:12:26 25 4
gpt4 key购买 nike

我不确定为什么,但我的代码波纹管没有为文件设置权限。不确定代码可能有什么问题。

系统:Windows XP 专业版 SP2。以管理员身份在管理员帐户中运行。最新的 Qt 框架和文件。

//Get file permissions of ref file.
QFile::Permissions qpPerm1;
qpPerm1 = QFile::permissions("E:/dir1/dir2/File1.txt");

//Set file permissions of a file.
bool isOK=0;
isOK = QFile::setPermissions("E:/dir4/dir5/file2.txt",qpPerm1);
qout << "Perms set? " << isOK << endl;

返回值为 TRUE... 声称它设置了权限,但实际上并没有。明确地说,file2.txt 是 file1.txt 的副本。我将 file1 的权限设置为某物,但运行我的代码后 file2.txt 具有不同的权限。

最佳答案

原样written QT 不支持在 Windows 上更改组的访问权限。要完全控制文件权限,请尝试使用位于安全描述符中的访问控制列表。

MSDN suggests这个:

To retrieve the security descriptor of a file or directory object, call the GetNamedSecurityInfo or GetSecurityInfo function. To change the security descriptor of a file or directory object, call the SetNamedSecurityInfo or SetSecurityInfo function.

我认为在您的情况下,您可以尝试从第一个文件获取 GetNamedSecurityInfo,然后将其传递给第二个文件的 SetNamedSecurityInfo。


您还可以分配 NULL ACL,它将重置所有组权限并授予每个人完全访问权限:

SetNamedSecurityInfoA("C:\file.txt", SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, NULL, NULL, NULL, NULL);

关于Qt set Permissions 不设置权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5021645/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com