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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top