Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. [SOLVED] how to use same db (SqLite) on all platforms?
Qt 6.12 LTS is out! See what's new in the release blog

[SOLVED] how to use same db (SqLite) on all platforms?

Scheduled Pinned Locked Moved Installation and Deployment
8 Posts 4 Posters 4.4k 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.
  • A Offline
    A Offline
    arsinte_andrei
    wrote on last edited by
    #1

    HI,
    I'm using a SqLite database and with full path to it is working ok on windows - but not on linux and not on android.
    @
    const QString dbType("QSQLITE");
    if(!QSqlDatabase::isDriverAvailable(dbType)){
    qCritical() <<dbType << " database module not available.";
    return false;
    }
    QString dbfile_path = QApplication::applicationDirPath() + "/db/test.db";
    QSqlDatabase mydb = QSqlDatabase::addDatabase(dbType);
    mydb.setDatabaseName(dbfile_path);
    mydb.open()
    @

    and so on...
    now if I will use as

    @
    QString dbfile_path = "c:/myproject/test/db/test.db";
    @

    it will work on windows but not on linux or android

    how can I do it to work on windows and on android and linux?
    also i see it does not copy the test.db who is in the db folder to the
    c:/myproject/build-test-Desktop_Qt_5_2_1_MinGW_32bit-Debug/debug/db - where is the place that to be

    if I will add this

    @qDebug() << dbfile_path;@

    this is the output

    c:/myproject/build-test-Desktop_Qt_5_2_1_MinGW_32bit-Debug/debug/db/test.db
    but it does not copy the file there so this path does not exist instead the file is located at
    c:/myproject/test/db/test.db

    please help me with this..
    thanks
    Andrew

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #2

      I would suggest to use "QStandardPaths":https://qt-project.org/doc/qt-5/qstandardpaths.html class to get the path to you storage location.
      In particular
      @
      QStandardPaths::DataLocation
      @

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

        Hi,

        If you want to have your database in a known path on all platform, you should use "QStandardPaths":http://qt-project.org/doc/qt-5/qstandardpaths.html with DataLocation.

        Most OS (even windows) will not allow you to create new files in the application folder from the application itself without e.g. administrator rights. And generally speaking, you should do that at all since every user could look/modify/destroy data of another user.

        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
        0
        • A Offline
          A Offline
          arsinte_andrei
          wrote on last edited by
          #4

          ok.. but how to move/copy this at that known location

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

            Generally you don't move it, you create the database directly there. If you are bundling an empty database with your application, just use QFile to copy it to the destination folder.

            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
            0
            • A Offline
              A Offline
              arsinte_andrei
              wrote on last edited by
              #6

              yes but how can be this done because on android I have to have a folder on the sdcard or on phone memory and on desktop I have to have that folder db made in the program's folder

              1 Reply Last reply
              0
              • C Offline
                C Offline
                clochydd
                wrote on last edited by
                #7

                You could save and read settings for every machine/user with QSettings.

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

                  this is true that you generally is nt a such need but in my case I wish to avoid having a import module on my program. any way the thing with path is very annoying . any way then how to create a new folder and new databese in it?? then i'l work for the update the tables from that database

                  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
                  • Unsolved