Include SQLite file in .apk package
-
I need to include an sqlite file in .apk package, which I can access from application code using QSqlDatabase class. Read-only access is sufficient. How can I do that?
Although this has been discussed here, the latest thread is pretty old. Let me remind you that I can't use the Qt Resource System because the embedded SQLite code isn't able to handle resource files.
-
Hi,
IIRC you have two options:
qrc then you create a temporary file from your sqlite database file
use "assets":http://qt-project.org/doc/qt-5/platform-notes-android.html#assets-file-system
Hope it helps
-
Thank you for your reply. The second option seems to be the best. I have put the SQLite file to assets and it is really present in the .apk package. However this code doesn't work:
@ QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("assets:/languages.db");
db.setConnectOptions("QSQLITE_OPEN_READONLY");@
subsequent call of db.open() fails. -
I don't know if the assets virtual file system is usable with QSqlDatabase. In between, what you can do is copy your database file in your application reserved data folder using QStandardPaths::DataLocation