Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QDir remove function
Qt 6.11 is out! See what's new in the release blog

QDir remove function

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.5k 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.
  • Allman 2A Offline
    Allman 2A Offline
    Allman 2
    wrote on last edited by Allman 2
    #1

    Hello QT- Developer,

    so in my HOME-Dir exist a folder which content should be deleted.

    It works fine when I debug through the code, but without debugging all files still exist.
    Well I have no idea why? Do you have some advice?

    Code:
    QStringList list;
    list << ".png" << ".jpg" << ".gif" << ".svg";
    QDir dir(path);
    dir.setNameFilters(list);
    dir.setFilter(QDir::Files);
    foreach(QString dirFile, dir.entryList())
    {
    dir.remove(dirFile);
    }

    THX ;)

    1 Reply Last reply
    0
    • Paul ColbyP Offline
      Paul ColbyP Offline
      Paul Colby
      wrote on last edited by Paul Colby
      #2

      Hi @Allman-2,

      How is path being set? I would think its more likely an issue with that than the code you've shown... but that's just a guess.

      First thing I'd do is add some debugging. Something like:

      qDebug() << QDir::currentPath()
      qDebug() << path;
      QDir dir(path);
      qDebug() << dir.absolutePath();
      dir.setNameFilters(list);
      dir.setFilter(QDir::Files);
      foreach(QString dirFile, dir.entryList())
      {
          qDebug() << dirFile;
          const bool removed = dir.remove(dirFile);
          qDebug() << removed;
      }
      

      Cheers.

      1 Reply Last reply
      3
      • Allman 2A Offline
        Allman 2A Offline
        Allman 2
        wrote on last edited by
        #3

        Hello,
        yes now I got the answer, because at that time the QDir is created there is now contend in
        this Path. There is a delay time.

        THX t all:

        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 Extensions
        • Unsolved