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
-
am set the current path to the database
and this is my currentpth code to the DatabaseQFile 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; }
-
am set the current path to the database
and this is my currentpth code to the DatabaseQFile 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; }
@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!
-
Thankyou@jsulm i can try the QStandardPaths::AppDataLocation
-
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.
-
@SGaist Thanks for your Suggestions .