Reputation: 315
I am developing an Android app with Qt.First.
I have run it on MinGW then posted it to Android build. My app makes select, insert, update operation on SQLite
database. This works well in MinGW , but when I exported to Android, there is no effect.
I have copied SQLite file to assets, but I can't read SQLite.
Upvotes: 3
Views: 653
Reputation: 32665
After adding the database file to assets folder, you should also add these to your .pro file :
deployment.files += myfile.sqlite
deployment.path = /assets
INSTALLS += deployment
But the files in assets are read-only. So you should first copy it to some other location. This could be done once on the first app start:
QFile dfile("./myfile.sqlite");
if (!dfile.exists())
{
QFile::copy("assets:/myfile.sqlite", "./myfile.sqlite");
QFile::setPermissions("./myfile.sqlite",QFile::WriteOwner | QFile::ReadOwner);
}
You can also use the Qt Resource system which is a cross-platform solution. By default, all Qt applications can access the contents of a qrc file using the :/
prefix or the URL scheme prefix, qrc:
. So all you need is to add the sqlite file to the project resource file and once copy it to some location and use it afterwards :
QFile dfile("./myfile.sqlite");
if (!dfile.exists())
{
QFile::copy(":/myfile.sqlite", "./myfile.sqlite");
QFile::setPermissions("./myfile.sqlite",QFile::WriteOwner | QFile::ReadOwner);
}
Upvotes: 1