12-17-2012 01:22 AM
I want to create sqlite db through my app.
I tried the below code but it returns false.. so how to create a DB and where does the default db file exists.?
db = QSqlDatabase::addDatabase("QSQLITE");
// Open databasee
bool dbOpen = db.open(); <- dbOpen is false here
12-17-2012 02:17 AM
In my application I created a SQLite database using an external application. In my code I check if a database file is present and if that's not the case, I copy the default database from the assets folder. It's pretty much the same logic as used in the quotes sample, so you might want to check that.
If you insist on completely creating your SQLite database in your code then I am not much of help I'm afraid.
12-17-2012 04:43 AM
I create the database like this:
QString databaseName = "dbname.db"; QString dataFolder = QDir::homePath(); QString databaseFileName = dataFolder + "/" + databaseName; QFile databaseFile(databaseFileName); databaseFile.open(QIODevice::ReadWrite); sqlDataAccess = new SqlDataAccess(databaseFileName);
took the code from some sample and modified it a bit.