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. Sqlite database access in Android app error
Forum Updated to NodeBB v4.3 + New Features

Sqlite database access in Android app error

Scheduled Pinned Locked Moved Solved Mobile and Embedded
3 Posts 2 Posters 1.3k 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
    gotronics
    wrote on last edited by
    #1

    hi can someone please assist me I can not access my database in my android app, I am able to embed it in assert file I am getting the following error
    W/libAccounts.so(27144): (null):0 ((null)): QSqlDatabasePrivate::database: unable to open database: "out of memory Error opening database"

    project file :

    android
    {
    my_files.path = /assets
    my_files.files = C:/Users/Gotora/Desktop/Acc_Software/Accounts/database.db
    INSTALLS += my_files
    }

    c++ file:

    QSqlDatabase db = QSqlDatabase::addDatabase( "QSQLITE" );

    QFile DbFile;
    QString DatabaseDataStoragePath = QStandardPaths::writableLocation(QStandardPaths::StandardLocation::AppDataLocation);
    DbFile.setFileName("assets:/database.sqlite");
    DbFile.copy(DatabaseDataStoragePath + "/database.sqlite");
    QFile::setPermissions(DatabaseDataStoragePath + "/database.sqlite", QFile::WriteOwner | QFile::ReadOwner);
    db.setDatabaseName( DatabaseDataStoragePath);```

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

      Hi,

      You should check the exact path where the database is copied and check whether you can really access it there.

      Just in case, you pass DatabaseDataStoragePath to setDatabaseName but that's the folder where the database is stored, not the database itself.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      G 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        You should check the exact path where the database is copied and check whether you can really access it there.

        Just in case, you pass DatabaseDataStoragePath to setDatabaseName but that's the folder where the database is stored, not the database itself.

        G Offline
        G Offline
        gotronics
        wrote on last edited by
        #3

        @SGaist

        thanks I solved this way
        in project file :
        android {
        data.files = C:/Users/Gotora/Desktop/Acc_Software/Accounts/MyDatabase.db
        data.path = /assets/database
        INSTALLS += data
        }

        in c++ file:

        QFile dfile("assets:/database/MyDatabase.db");
        QString filePath = QStandardPaths::writableLocation( QStandardPaths::StandardLocation::AppLocalDataLocation );
        filePath.append( "/MyDatabase.db");
        if (dfile.exists()) {
        if( QFile::exists( filePath ) )
        QFile::remove( filePath );

              if( dfile.copy( filePath ) )
                  QFile::setPermissions( filePath, QFile::WriteOwner | QFile::ReadOwner );
        
          }
          db.setDatabaseName( filePath );
        
        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