Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Include SQLite file in .apk package
Forum Updated to NodeBB v4.3 + New Features

Include SQLite file in .apk package

Scheduled Pinned Locked Moved Mobile and Embedded
4 Posts 2 Posters 3.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    ondrejandrej
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • O Offline
        O Offline
        ondrejandrej
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved