Out of this output we can see that the database-connection works, and that the connection is successfully removed. The file could not be removed Access denied The database- and app versions not equal. The console output this produces is Successfully connected to database. QDebug().noquote() << (f.remove() ? "The database file was successfully removed" : QString("The file could not be removed ") + f.errorString()) QDebug() << QSqlDatabase::connectionNames() QDebug() << (copyDatabase ? "The database- and app versions are not equal." : "The database- and app versions are equal.") << QCritical().noquote() app_version = įor(int i = 0 i < 3 i++) db_version = query.value(i).toInt() ĬopyDatabase = app_version != db_version QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE") //not dbConnectionĭb.setDatabaseName(f.fileName()) //if the database file doesn't exist yet, it will create it QFile f(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/database.sqlite") Can you maybe figure out what I am doing wrong? bool copyDatabase = true The only case when the file gets deleted is if i delete it myself, replace it and then delete the file by Qt before I open the database.īut once I have opened the database I can't delete it any longer (using Qt), even when I restart the pc. This even happens when I restart the computer and then try to delete the file before I open the database (in Qt, as user it is no problem for me to delete the file). The weird thing is that it even says access denied, when I try to delete the file before I open the database. It always says Access denied, when I try to delete it. Opening the database and retrieving the version works fine, but I can't figure out why I can't delete the file. What I want to do is delete that sqlitefile (in order to replace it) if it has an older version than the application. I tried both MinGW and Visual Studio Compiler, but always get the same error. My System is Qt5.8 with QtCreator in the newest version and Windows 10. This code opens a local sqlite 3 file as SQLite Databse in Qt, and checks the version of that file (included in a table in the database.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |