6

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?

László Papp
  • 51,870
  • 39
  • 111
  • 135
user3490755
  • 955
  • 2
  • 15
  • 33
  • Always check the return value. Cause could be permission or locking by being in use or wrong path. – user2672165 Apr 24 '14 at 18:46
  • What does the return value of the remove call? See `if(!rmFile->remove()) qDebug() << rmFile.errorString();` Also, in this special case, the instance is an overkill. You can call the static method directly. – László Papp Apr 24 '14 at 18:46
  • 1
    If you are under Mac, "/path/to/app/Application.app" points to a directory, and not to the file, no? – vahancho Apr 24 '14 at 18:48

1 Answers1

7

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.

László Papp
  • 51,870
  • 39
  • 111
  • 135