Solved QSqlDatabase setDatabaseName qrc
-
this is my code:
QSqlDatabase sqliteDatabase =QSqlDatabase::addDatabase("QSQLITE");;
QString dateBaseFile(":/file/global.db");
QFile file(dateBaseFile);
if (!file.exists())
{
return;
}sqliteDatabase.setDatabaseName(dateBaseFile); bool bOpenFlag = sqliteDatabase.open();
if (!bOpenFlag)
{
qDebug()<< sqliteDatabase.lastError();
}
dateBaseFile is copied from QRC, and the path has been checked to be correct, but the database cannot be opened. The Error information is QSqlError("-1", "Error opening database", "out of memory").Has anyone ever experienced this before? -
You can't open a db from a resource - sqlite doesn't know anything about this. You have to copy it to a local file.
-
I don't think sqlite can read a qrc file.
-
@Christian-Ehrlicher
Ok, thanks for your reply