Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QFile::remove not removing file?

Having a strange problem when trying to remove a file i just downloaded with Qt.

My code:

QString location = "/path/to/app/Application.app";
QFile *rmFile = new QFile(location);
rmFile->remove();

File is not being removed.

Any ideas what could be wrong?

like image 861
user3490755 Avatar asked Apr 24 '14 18:04

user3490755


1 Answers

If it is a directory as it seems to be, you wish to use the following API with Qt 5:

bool QDir::removeRecursively()

as opposed to QFile. Therefore, you would be writing something like this:

QString location = "/path/to/app/Application.app";
QDir *rmDir = new QDir(location);
rmDir->removeRecursively();

Note that I would not personally use a heap object just for this. Stack object would suffice in this simple case.

like image 196
lpapp Avatar answered Oct 18 '22 02:10

lpapp