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

Qt Code:
  1. void Database::load()
  2. {
  3. ...
  4. dbFileName = "database.sqlite"; // QString
  5. dbFile.setFileName(dbFileName); // QFile
  6. QSqlDatabase sqldb = QSqlDatabase::addDatabase("QSQLITE");
  7. sqldb.setDatabaseName(dbFileName);
  8. dbIsOpen = sqldb.open();
  9. dbConName = sqldb.connectionName();
  10. ...
  11. }
  12.  
  13. void Database::unload()
  14. {
  15. QSqlDatabase::database( dbConName, false ).close();
  16. QSqlDatabase::removeDatabase( dbConName );
  17. bool removed = dbFile.remove();
  18. }
To copy to clipboard, switch view to plain text mode