QFileInfo :: isWritable()在Windows 7上以完全权限返回false [英] QFileInfo::isWritable() returning false at full permissions on windows 7

查看:167
本文介绍了QFileInfo :: isWritable()在Windows 7上以完全权限返回false的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

QFile file(filePath);
QFileInfo fileInfo(file);

file.open(QIODevice::ReadWrite); //or WriteOnly

if(!fileInfo.isWritable())
{
    //Log error
}
else
{
    //Save to file
}

问题是,文件路径具有完全访问权限,文件已创建且可写,但是isWritable()仍返回false.如果删除写访问检查并仅写入文件,则写入成功. QFile :: open也返回true.有什么想法吗?

Problem is, filepath has full access, file is created and writable and yet isWritable() still return false. If I remove the write access check and simply write to file, writing is successful. QFile::open also returns true. Any ideas?

推荐答案

QFileInfo::isWritable()不是用于检查打开的文件是否可写,而是用于检查当前用户对该文件的许可.如果只想查看打开文件操作是否成功,请检查调用QFile::open()的返回值.如果返回true,则文件准备就绪.如果错误返回false,请执行错误处理.

QFileInfo::isWritable() is not for checking if a open file is writable, it's to check the permission of current user on the file. If all you want is the see if the open file operation succeeded, check the return value from the call QFile::open(). If it returns true then the file is ready to write. Do your error handling if it returns false.

我不知道为什么isWritable()在您的情况下失败. Windows可能认为文件已打开,因此无法通过另一个open()调用写入.如果您确实要检查权限,请在打开文件之前调用isWritable().

I don't know why isWritable() fails in your case. It may be that Windows thinks the file has been open thus not writable from another open() call. If you really want to check permission, call isWritable() before opening the file.

这篇关于QFileInfo :: isWritable()在Windows 7上以完全权限返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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