Solved How to add sqlite to QResource
-
I added an sqlite to qresource. When I used db.setDataBaseName(":/new/logindb.sqlite");
When I did that it didn't work.
Or is there any other way that I make the database to work on any PC because am using its path on my system which will not work on other systems. -
@gblessed your resource system is in the best case readonly. So simply opening your database from there won't work.
I suggest on startup copying the db file to the local drive, if it doesn't exist.
QStandardPaths is the class you should check out to identify read/writeable path of your system
-
@J.Hilk
Thanks
A little code sample may help me out -
-
@gblessed
untested, from the top of my head:QString targetDb = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation).append("/logindb.sqlite"); if(!QFile::exists(targetDb){ QFile::copy(":/new/logindb.sqlite", targetDb); }
-
@gblessed please be aware that any changes (updates/deletions) you do to the DB will be overwritten (lost!) next time you extract the DB from QResource into filesystem... be careful
-
Thanks friends its solved