Please nominate your Qt Champions for 2021!

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.

  • Lifetime Qt Champion


    IIRC you have two options:

    qrc then you create a temporary file from your sqlite database file

    use "assets":

    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");
    subsequent call of fails.

  • Lifetime Qt Champion

    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

Log in to reply