• Why is there no function QDir::isWritable()? Is there another way to find out if a directory is writable?

  • @QFileInfo fi(path);

    if(fi.isDir() && fi.isWritable()){
    qDebug() << "Voila";
    qDebug() << "Can't write! sucks";

  • On Windows, this returns false even on my home folder!?

    Is there another way?

  • @#include <QtGui/QApplication>
    #include <QtCore/QFileInfo>
    #include <QtCore/QDebug>
    #include <QtCore/QDir>

    int main(int argc, char* argv[])
    QApplication app(argc, argv);
    QFileInfo fi(QDir::homePath());
    if (fi.isDir() && fi.isWritable()){
    qDebug() << "voila";
    qDebug() << "not so good";

    For me this whole indeed printed "voila"

  • By the way, I'm on Vista x64 with Qt 4.6.1 and VS2008.

  • I tried this and it worked. I must be doing something else wrong in my original program, but I just can't figure out what!

    My code is like this:

    QFileInfo fi(QFileInfo(outputDir).path());
    if (!fi.isWritable())
    QMessageBox::warning(NULL, "Error", "You must have write permission to the output directory.", QMessageBox::Ok, NULL);

    On Linux it works, but on windows I get the error message every time.

  • @QFileInfo fi(QFileInfo(outputDir).path());@

    Regarding above line from your code.

    If outputDir="/foo/bar/blah"; then your code is not checking whether blah is writable. It is checking bar. Because your fi will be pointing to foo/bar and not foo/bar/blah.

  • I tried adding a "/" and got the same results.

  • What I'm trying to point out is that why can't you do
    QFileInfo fi(outputDir) vs

    QFileInfo fi(QFileInfo(outputDir).path()) ?@

  • I'm sorry, I made a mistake. I meant outputPath (a directory + filename), not outputDir (just a directory).

  • Well my only suggestion is to print out all the variables step by step and check the return values of isValid(), isDir(), exists(), isReadable(), etc... and try to figure it out.

    I don't think you are doing anything wrong.

  • OK. Thanks for the help.

  • I know I started this thread a long time ago, but I just stumbled over the answer while browsing the documentation for QFile. There, it says, (http://doc.qt.nokia.com/4.7/qfile.html#platform-specific-issues)

    "File permissions are handled differently on Linux/Mac OS X and Windows. In a non writable directory on Linux, files cannot be created. This is not always the case on Windows, where, for instance, the 'My Documents' directory usually is not writable, but it is still possible to create files in it."

    It appears that it really is not writable, but I could create files in it.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.