Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Diagnosing QDir::rmdir failure
Qt 6.12 LTS is out! See what's new in the release blog

Diagnosing QDir::rmdir failure

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 3.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Violet Giraffe
    wrote on last edited by
    #1

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

    @bool removeFolder (const QString& path)
    {
    QDir dir(path);
    assert(dir.exists());
    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.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      thEClaw
      wrote on last edited by
      #2

      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:
      @QDir::removeRecursively()@

      1 Reply Last reply
      0
      • V Offline
        V Offline
        Violet Giraffe
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt
        • Unsolved