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 673 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 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.HilkJ 1 Reply Last reply
    0
    • G gblessed

      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.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on 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
      3
      • J.HilkJ J.Hilk

        @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 last edited by
        #3

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

        Pablo J. RoginaP J.HilkJ 3 Replies Last reply
        0
        • G gblessed

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

          Pablo J. RoginaP Offline
          Pablo J. RoginaP Offline
          Pablo J. Rogina
          wrote on 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

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

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on 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

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

              Pablo J. RoginaP Offline
              Pablo J. RoginaP Offline
              Pablo J. Rogina
              wrote on 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 last edited by
                #7

                Thanks friends its solved

                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