Solved unable to delete file using dir->remove() function
-
In the following code filenames and directories are stored in QListWidget (as shown in image)
I'm unable to delete the file
(Basically an attempt to delete file present in more than one folder.)for(int row=0; row< ui->listWidget_dirList->count(); row++) { QListWidgetItem *item= ui->listWidget_dirList->item(row); if(item->checkState()==2) { qDebug()<< item->text(); dir= new QDir(item->text()); qDebug()<< dir->remove(filename); //shows 'false' on console } else { filename= item->text(); } }
-
Hi,
From the looks of it, you are trying to build a QDir with a file path which seem strange. Wouldn't QFile::remove be a better fit in your applicaation ?
On a side note, you are leaking QDir objects. You always create a new QDir and do not delete it. From the looks of it, a local stack object should be enough (but again, consider first QFile9
-
@SGaist
how can I use QFile::remove() as, its argument demands the filename, but I don't want the file to be removed from all directories. I'm leaving it for user to select those locations from which they want to remove. and thank you for your side note. -
From the looks of it, you are providing the user with a list of file paths, are you not ?
-
@SGaist
yes -
Then you already have the full paths to each file your users would like to delete hence my proposition of using QFile.
-
@SGaist
it solved my problem
thanks a ton:))))