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
Forum Update on Monday, May 27th 2025

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.
  • R Offline
    R Offline
    Robey Mardon
    wrote on 6 May 2015, 15:40 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 6 May 2015, 16:27 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");

      R 1 Reply Last reply 6 May 2015, 16:39
      0
      • L Leonardo
        6 May 2015, 16:27

        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");

        R Offline
        R Offline
        Robey Mardon
        wrote on 6 May 2015, 16:39 last edited by Robey Mardon 5 Jun 2015, 16:45
        #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
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 6 May 2015, 20:40 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

          3/4

          6 May 2015, 16:39

          • Login

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