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
-
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
-
From the looks of it, you are providing the user with a list of file paths, are you not ?
-
Then you already have the full paths to each file your users would like to delete hence my proposition of using QFile.
-
Then you already have the full paths to each file your users would like to delete hence my proposition of using QFile.