在Vista 64上用户桌面的QFileInfo权限不正确 [英] Incorrect QFileInfo permissions for user desktop on vista 64

查看:135
本文介绍了在Vista 64上用户桌面的QFileInfo权限不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码来确定是否可以使用QFileInfo写入特定目录:

I am using the following code to determine if I can write to a specific directory using QFileInfo:

QFileInfo dinfo(dirname);
if (dinfo.exists())
  valid = dinfo.isWritable()

不幸的是,当我在Vista 64上传递当前用户桌面的路径时:

Unfortunately, when I pass in the path of the current user's desktop on Vista 64:

C:\Users\USERNAME\Desktop

QFileInfo :: isWritable()返回false.但是,如果我将另一个目录(例如C:\ Temp)传递给它,则返回true.我从QFileInfo对象请求了5555的目录权限(任何人都不能写).该代码可以在包括Windows XP在内的其他平台上正常工作.任何人都对这里可能发生的事情有任何想法.

QFileInfo::isWritable() returns false. However, if I pass it another directory (say C:\Temp) it returns true. I requested the directory permissions from the QFileInfo object which were 5555 (not writable by anyone). This code works as expected on other platforms including Windows XP. Anybody have any ideas as to what might be going on here.

作为参考,如果删除支票,我实际上可以将文件保存到该位置而没有问题.

As a point of reference, if I remove the check I can actually save the file to that location without a problem.

推荐答案

因此,在Qt的任务跟踪器中进行了一些挖掘之后,我发现QFileInfo :: isWritable()仅对文件有效,而对目录无效.通过更改代码以询问是否可以创建感兴趣的文件,而不是询问目录是否可写,我可以实现所需的结果:

So, after a bit of digging through the Task Tracker at Qt, I discovered that QFileInfo::isWritable() is only valid for use on files and not directories. By changing the code to ask if I could create the file of interest instead of asking if the directory is writable, I was able to achieve the desired outcome:

QDir dir(dirname);
if (dir.exists())
{
  QFileInfo finfo(dir.absoluteFilePath(fname));
  valid = finfo.isWritable();
} 

谢谢.

这篇关于在Vista 64上用户桌面的QFileInfo权限不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆