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. Adding db to resources
QtWS25 Last Chance

Adding db to resources

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 6.2k 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.
  • K Offline
    K Offline
    kitten
    wrote on last edited by
    #1

    hi to every one
    i want to know can i add my qsqlite database that it is near of my program to my resources?
    if it can't done.can i change its path to another folder , because when i use setdatabasename function i cant set its path and it only searches application dir path
    i want to be :
    app dir path/Data/1.db

    www.kitten.mihanblog.com

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      You can not put a database file into the Qt resources (qrc). The reason is simply that Qt uses the unmodified sqlite library and passes the path to the database file to sqlite. And as sqlite is not aware of Qt at all and its resource system, it cannot find the file.

      Additionally, even if it would work, the database in the resources would be read only!

      What you can do is: Store the database in the resources and before using it the first time copy it to the real world file system. QFile is aware of the resources and can copy between those and the file system. Just make sure that you do not overwrite a modified database of the file system copy with the resource version.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      2
      • K Offline
        K Offline
        kitten
        wrote on last edited by
        #3

        can i move it to another directory?

        www.kitten.mihanblog.com

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          Sure, you can put it anywhere you have write rights on the file system.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kitten
            wrote on last edited by
            #5

            but in which function can i set its address?because setdatabasename function only sets a db name

            www.kitten.mihanblog.com

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              How do you figure that? Set database name takes a complete path for the SQLite driver.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #7

                In case of SQLite - and only there - setDatabaseName() takes the full path to the database file. It may be a single file name, in that case it is located in "the current directory", or some relative or absolute path + file name.

                PS: I've added a "doc note":/doc/qt-4.8/qsqldatabase.html#notes

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #8

                  Actually, the same goes for the Borland Interbase (QIBASE) driver: it also takes a full file path. And I wrote an MSACCESS driver that did the same, but that one is not in Qt, so it does not count ;-)

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #9

                    Good to know, I've updated the note.

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    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