Solved QDir remove function
-
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 ;)
-
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.
-
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: