View Full Version : QFile::remove() fails only on Windows?

13th February 2013, 17:24
The following code fails at dbFile.remove(), but only on Windows (at least Win7). Any clues why? I am truly sorry I cannot provide a minimal example. I thought maybe it was that the sql database is somehow still accessing the file even after I close and remove it, but I dunno. I am just frustrated and out of time and thought you experts might have conjectures.

The file in question has read/write access by the user, and the permissions are 0x6666.

The error string after dbFile.remove() is: "The process cannot access the file because it is being used by another process."

void Database::load()
dbFileName = "database.sqlite"; // QString
dbFile.setFileName(dbFileName); // QFile
QSqlDatabase sqldb = QSqlDatabase::addDatabase("QSQLITE");
dbIsOpen = sqldb.open();
dbConName = sqldb.connectionName();

void Database::unload()
QSqlDatabase::database( dbConName, false ).close();
QSqlDatabase::removeDatabase( dbConName );
bool removed = dbFile.remove();