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. How to use SQLite on Qt Android
Qt 6.11 is out! See what's new in the release blog

How to use SQLite on Qt Android

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
2 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.
  • aldo praherdaA Offline
    aldo praherdaA Offline
    aldo praherda
    wrote on last edited by
    #1

    I want to use SQLite on Qt Android 5.6, the db file is in the Qt resource and will be copied to write able location on android but it failed when copying db from resource to external path

    db = QSqlDatabase::addDatabase( "QSQLITE","MyConnection" );    
    QString filePath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
    filePath.append( "/"+dbname);
    
    QFile dfile(":/android/assets/"+dbname);
    
    if (dfile.exists())
    {
        //dfile.copy("./"+dbname);
        //QFile::setPermissions("./"+dbname,QFile::WriteOwner | QFile::ReadOwner);
        if( QFile::exists( filePath ) )
            QFile::remove( filePath );
    
        if( dfile.copy( filePath ) ){
            QFile::setPermissions( filePath, QFile::WriteOwner | QFile::ReadOwner );
        }else{
            QMessageBox::information(0,"Info","Error copying "+dfile.fileName()+" to " +filePath);
        }
    
    }else{
        QMessageBox::information(0,"Info",dfile.fileName()+" is missing");
    }
    
    db.setDatabaseName(filePath);
    
    1 Reply Last reply
    0
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You could call dfile.error() to see what the problem was.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      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