QFileInfo::isWritable() returning false at full permissions on windows 7

谁说我不能喝 提交于 2019-12-24 02:43:55

问题


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

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

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

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?


回答1:


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.

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.




回答2:


Try to run your program as administrator (with right click on it). Maybe this problem is caused by the UAC.



来源:https://stackoverflow.com/questions/10143207/qfileinfoiswritable-returning-false-at-full-permissions-on-windows-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!