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. How to add sqlite to QResource
Forum Updated to NodeBB v4.3 + New Features

How to add sqlite to QResource

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 659 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.
  • G Offline
    G Offline
    gblessed
    wrote on 18 Jul 2019, 12:32 last edited by
    #1

    I added an sqlite to qresource. When I used db.setDataBaseName(":/new/logindb.sqlite");
    When I did that it didn't work.
    Or is there any other way that I make the database to work on any PC because am using its path on my system which will not work on other systems.

    J 1 Reply Last reply 18 Jul 2019, 12:37
    0
    • G gblessed
      18 Jul 2019, 12:32

      I added an sqlite to qresource. When I used db.setDataBaseName(":/new/logindb.sqlite");
      When I did that it didn't work.
      Or is there any other way that I make the database to work on any PC because am using its path on my system which will not work on other systems.

      J Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 18 Jul 2019, 12:37 last edited by
      #2

      @gblessed your resource system is in the best case readonly. So simply opening your database from there won't work.

      I suggest on startup copying the db file to the local drive, if it doesn't exist.

      QStandardPaths is the class you should check out to identify read/writeable path of your system


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      G 1 Reply Last reply 18 Jul 2019, 12:44
      3
      • J J.Hilk
        18 Jul 2019, 12:37

        @gblessed your resource system is in the best case readonly. So simply opening your database from there won't work.

        I suggest on startup copying the db file to the local drive, if it doesn't exist.

        QStandardPaths is the class you should check out to identify read/writeable path of your system

        G Offline
        G Offline
        gblessed
        wrote on 18 Jul 2019, 12:44 last edited by
        #3

        @J.Hilk
        Thanks
        A little code sample may help me out

        P J 3 Replies Last reply 18 Jul 2019, 12:48
        0
        • G gblessed
          18 Jul 2019, 12:44

          @J.Hilk
          Thanks
          A little code sample may help me out

          P Offline
          P Offline
          Pablo J. Rogina
          wrote on 18 Jul 2019, 12:48 last edited by
          #4

          @gblessed what about this previous post?

          Upvote the answer(s) that helped you solve the issue
          Use "Topic Tools" button to mark your post as Solved
          Add screenshots via postimage.org
          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          2
          • G gblessed
            18 Jul 2019, 12:44

            @J.Hilk
            Thanks
            A little code sample may help me out

            J Offline
            J Offline
            J.Hilk
            Moderators
            wrote on 18 Jul 2019, 12:50 last edited by
            #5

            @gblessed
            untested, from the top of my head:

            QString targetDb = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation).append("/logindb.sqlite");
            if(!QFile::exists(targetDb){
                QFile::copy(":/new/logindb.sqlite", targetDb);
            }
            

            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            1
            • G gblessed
              18 Jul 2019, 12:44

              @J.Hilk
              Thanks
              A little code sample may help me out

              P Offline
              P Offline
              Pablo J. Rogina
              wrote on 18 Jul 2019, 12:53 last edited by
              #6

              @gblessed please be aware that any changes (updates/deletions) you do to the DB will be overwritten (lost!) next time you extract the DB from QResource into filesystem... be careful

              Upvote the answer(s) that helped you solve the issue
              Use "Topic Tools" button to mark your post as Solved
              Add screenshots via postimage.org
              Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              1
              • G Offline
                G Offline
                gblessed
                wrote on 23 Jul 2019, 05:32 last edited by
                #7

                Thanks friends its solved

                1 Reply Last reply
                0

                1/7

                18 Jul 2019, 12:32

                • Login

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