Search code examples
c++qtqtcoreqfileqdir

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?


Solution

  • 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.