Below is what I do for clearing and compressing my SQLite database files in Qt. Usually when you delete some entries from a SQLite database, it does not get deleted physically but instead it just gets marked as deleted and is not retrieved in queries. The good thing about this is that it works fast. But the obvious downside is the fact that the free space is not released. To release the space occupied by deleted files you need to do the following:
QMessageBox::critical(this, “Error”, “Can’t compress database.”);
Note that db is your QSqlDatabase and VACUUM is the SQLite command responsible for compressing the database.