Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. SQLite database file within qrc

SQLite database file within qrc

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.5k Views
  • 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.
  • Robey MardonR Offline
    Robey MardonR Offline
    Robey Mardon
    wrote on last edited by
    #1

    Is it possible to insert a SQLite .db file in a resource .qrc file?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      Leonardo
      wrote on last edited by
      #2

      I have never tried, but if it's a read only database, there's no reason for it not to be possible. Just try:

      db.setDatabaseName(":/database.db");

      Robey MardonR 1 Reply Last reply
      0
      • L Leonardo

        I have never tried, but if it's a read only database, there's no reason for it not to be possible. Just try:

        db.setDatabaseName(":/database.db");

        Robey MardonR Offline
        Robey MardonR Offline
        Robey Mardon
        wrote on last edited by Robey Mardon
        #3

        @Leonardo Unfortunately it doesn't seems to work. I tried the way you said and nothing appears, then I tried using the full path for the database file and worked.

        I just realized that it's not possible:

        SQLite databases cannot be stored in the Qt resource system. You must put it into regular files and distribute them along your application.
        The reason is simple: The database name is just the path to the file. Qt does not intercept the file name but hands it over directly to the SQLite functions (by calling toUtf8() on the “path”), which in turn try to open that file – and will eventually fail, of course.
        Also, keep in mind that a file in a resource is read-only, you would never be able to write to that database.
        goetz

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

          Hi,

          Technically it can be embedded, BUT you can't make the QtSql module read it even less write it. What you can do however is put a copy of that "embedded" database in a suitable folder and then use it from your application. To get a suitable folder, use QStandardPaths.

          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

          • Login

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