Search code examples
qtfile-permissionsvista64

Incorrect QFileInfo permissions for user desktop on vista 64


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()

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

C:\Users\USERNAME\Desktop

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.


Solution

  • 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();
    } 
    

    Thanks.