Important: Please read the Qt Code of Conduct -

Diagnosing QDir::rmdir failure

  • I'm using the following code to delete an empty folder on Linux:

    @bool removeFolder (const QString& path)
    QDir dir(path);
    return dir.rmdir(".");

    For some reason it sometimes returns false (for specific folders, but those folders don't seem to be wrong in any way). If I subsequently use ::rmdir from <unistd.h> to remove the same folder, it succeeds.
    How can I tell why QDir::rmdir is failing?

    This never happened on Windows so far, QDir::rmdir just works.

  • Are you certain that a seemingly non-deletable directory does not contain hidden objects (starting with a ".")? QDir::rmdir() cannot handle non-empty directories.

    If you are using Qt5, you could use a different function:

  • I am certain, I also have this assert and it never triggers:

    @assert(dir.entryList(QDir::NoDotAndDotDot | QDir::Hidden | QDir::System).isEmpty());@

    And, like I said, ::rmdir deletes the folder and indicates no error. I don't believe it can delete non-empty folders.

    If it was Windows I would step into QDir source when debugging and would see why exactly it is failing. Unfortunately, I'm new to Linux and don't know how to make Qt debuggable.

Log in to reply