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. I Am Working on android application by using Sqlite Database in Qt side and The database data working on the desktop when its come to the android mobile setup database is not recognized
Forum Updated to NodeBB v4.3 + New Features

I Am Working on android application by using Sqlite Database in Qt side and The database data working on the desktop when its come to the android mobile setup database is not recognized

Scheduled Pinned Locked Moved Solved Mobile and Embedded
5 Posts 3 Posters 559 Views 2 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.
  • naveendraKumarN Offline
    naveendraKumarN Offline
    naveendraKumar
    wrote on last edited by
    #1

    am set the current path to the database
    and this is my currentpth code to the Database

    QFile file;

    //connection to the sql Database
    
    qDebug()<<"Connect Database"<<Qt::endl;
    m_database=QSqlDatabase::addDatabase("QSQLITE");
    QString currentpath=QDir::currentPath()+"/Database.db";
    qDebug()<<"Current path"<<currentpath<<Qt::endl;
    
    file.setFileName(currentpath);
    file.open(QIODevice::ReadWrite);
    
    QSqlQuery m_query(m_database);
    m_database.setDatabaseName(currentpath);
    m_database.open();
    if(m_database.isOpen()){
        qDebug()<<"employee Database is open"<<Qt::endl;
    }
    else{
        qDebug()<<"employee Database is Not Open"<<Qt::endl;
    }
    
    QString qry("CREATE TABLE PthinksEmployee(empName VARCHAR(20) NOT NULL,empId VARCHAR(20) NOT NULL,eMail VARCHAR(30) NOT NULL,password VARCHAR(30) NOT NULL,confirmPassword VARCHAR(30) NOT NULL,Primary KEY(empId));");
    if(m_query.exec(qry)){
        qDebug()<<"Table Created Successful"<<m_query.lastError()<<Qt::endl;
    }
    else{
        qDebug()<<"Table is Not Created"<<Qt::endl;
    }
    
    jsulmJ 1 Reply Last reply
    0
    • naveendraKumarN naveendraKumar

      am set the current path to the database
      and this is my currentpth code to the Database

      QFile file;

      //connection to the sql Database
      
      qDebug()<<"Connect Database"<<Qt::endl;
      m_database=QSqlDatabase::addDatabase("QSQLITE");
      QString currentpath=QDir::currentPath()+"/Database.db";
      qDebug()<<"Current path"<<currentpath<<Qt::endl;
      
      file.setFileName(currentpath);
      file.open(QIODevice::ReadWrite);
      
      QSqlQuery m_query(m_database);
      m_database.setDatabaseName(currentpath);
      m_database.open();
      if(m_database.isOpen()){
          qDebug()<<"employee Database is open"<<Qt::endl;
      }
      else{
          qDebug()<<"employee Database is Not Open"<<Qt::endl;
      }
      
      QString qry("CREATE TABLE PthinksEmployee(empName VARCHAR(20) NOT NULL,empId VARCHAR(20) NOT NULL,eMail VARCHAR(30) NOT NULL,password VARCHAR(30) NOT NULL,confirmPassword VARCHAR(30) NOT NULL,Primary KEY(empId));");
      if(m_query.exec(qry)){
          qDebug()<<"Table Created Successful"<<m_query.lastError()<<Qt::endl;
      }
      else{
          qDebug()<<"Table is Not Created"<<Qt::endl;
      }
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @naveendraKumar said in I Am Working on android application by using Sqlite Database in Qt side and The database data working on the desktop when its come to the android mobile setup database is not recognized:

      QString currentpath=QDir::currentPath()+"/Database.db";

      This is a very bad idea! Especially on mobile platforms. You should store your database files in a location meant to be used by the application to store its data. See https://doc.qt.io/qt-6/qstandardpaths.html to learn how to get path to such a folder (hint: use QStandardPaths::AppDataLocation).

      And please use shorter headlines!

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

      1 Reply Last reply
      1
      • naveendraKumarN Offline
        naveendraKumarN Offline
        naveendraKumar
        wrote on last edited by
        #3

        Thankyou@jsulm i can try the QStandardPaths::AppDataLocation

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

          Hi and welcome to devnet,

          In addition to what @jsulm suggested, check whether the folder exists and create it otherwise. That's normal. The path is correct but there's no reason for a mobile OS to create them preemptively as not all applications will make use of them.

          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
          1
          • naveendraKumarN Offline
            naveendraKumarN Offline
            naveendraKumar
            wrote on last edited by
            #5

            @SGaist Thanks for your Suggestions .

            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