Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. (solved) Qt 5.2: Problem deploying sqlite database to my android device
QtWS25 Last Chance

(solved) Qt 5.2: Problem deploying sqlite database to my android device

Scheduled Pinned Locked Moved Mobile and Embedded
9 Posts 6 Posters 9.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.
  • N Offline
    N Offline
    nando76
    wrote on 13 Jan 2014, 13:32 last edited by
    #1

    Hi,

    i have problems deploying my sqlite database to an android device.
    i tryed to did it "as described here.":http://qt-project.org/doc/qt-5/platform-notes-android.html
    The database is located in a subdirectory called database/MyDatabase.db in my project folder.

    I added the following lines in .pro file:
    @android {
    folder_01.source = database
    folder_01.target = .
    DEPLOYMENTFOLDERS = folder_01
    }@

    This works and i can see the database folder including the file MyDatabase.db in the android-build/assets folder.

    In code i try to open the database like this:
    @... setDatabaseName("assets:/database/MyDatabase.db");@

    But always getting the error:
    out of memory Error opening database

    It seems somehow the assets:/database/MyDatabase.db is not working....

    Any ideas?

    Greetings,
    Nando

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kolegs
      wrote on 13 Jan 2014, 18:25 last edited by
      #2

      I can see you set database name but what about loading a driver and opening it.
      @
      QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
      db.setDatabaseName("assets:/database/MyDatabase.db");
      db.open();@

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nando76
        wrote on 13 Jan 2014, 18:35 last edited by
        #3

        Hi, yes i do this like this:
        The code works fine on Desktop:

        @
        const QString type("QSQLITE");

        if(!QSqlDatabase::isDriverAvailable(type))
        {
            qCritical() << type << " database module not available.";
            return false;
        }
        
        m_DB = QSqlDatabase::addDatabase(type);
        m_databasePath = "assets:/database/MyDatabase.db";
        m_DB.setDatabaseName(m_databasePath);
        if(!m_DB.open())
        {
            qCritical() << "couldn't connect to database Error[" <<
                           m_DB.lastError().text() << "]";
            return false;
        }
        qDebug() << "succsessfully connected to database " << m_databasePath;
        

        @

        [quote author="kolegs" date="1389637543"]I can see you set database name but what about loading a driver and opening it.
        @
        QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
        db.setDatabaseName("assets:/database/MyDatabase.db");
        db.open();@[/quote]

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kolegs
          wrote on 13 Jan 2014, 18:48 last edited by
          #4

          I'm not sure but aren't assets files readonly, and I belive database need to be readwrite. I use the code below to copy file first and the open it:
          @QFile dfile("assets:/db/database-last.db3");
          if (dfile.exists())
          {
          dfile.copy("./database-last.db3");
          QFile::setPermissions("./database-last.db3",QFile::WriteOwner | QFile::ReadOwner);
          }@
          @QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
          db.setDatabaseName("./database-last.db3");
          db.open();@

          and in my .pro file
          @deployment.files += database-last.db3
          deployment.path = /assets/db
          INSTALLS += deployment
          @

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nando76
            wrote on 13 Jan 2014, 19:39 last edited by
            #5

            Yo are the man!!!! ;-)
            Thank you very much this works great!!!

            [quote author="kolegs" date="1389638889"]I'm not sure but aren't assets files readonly, and I belive database need to be readwrite. I use the code below to copy file first and the open it:
            @QFile dfile("assets:/db/database-last.db3");
            if (dfile.exists())
            {
            dfile.copy("./database-last.db3");
            QFile::setPermissions("./database-last.db3",QFile::WriteOwner | QFile::ReadOwner);
            }@
            @QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
            db.setDatabaseName("./database-last.db3");
            db.open();@

            and in my .pro file
            @deployment.files += database-last.db3
            deployment.path = /assets/db
            INSTALLS += deployment
            @[/quote]

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jcmayorga
              wrote on 20 Jan 2014, 05:03 last edited by
              #6

              Excellent!

              I've been looking for this solution for two days and found it!

              thank you very much!

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jordi122
                wrote on 14 Feb 2014, 07:38 last edited by
                #7

                Great help!!

                Thank you!!

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  Muhammad
                  wrote on 3 Jul 2014, 00:06 last edited by
                  #8

                  @nando76 and @kolegs!, thank you very much guys that was really helpful.

                  I don't have endpoint, I just have Checkpoints.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andy65007
                    wrote on 17 Nov 2014, 10:26 last edited by
                    #9

                    thanks a lot!! this problem stuck me for several days.
                    BTW, there are two database files after copy it, is there a better idear for this?

                    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