Adding db to resources
-
hi to every one
i want to know can i add my qsqlite database that it is near of my program to my resources?
if it can't done.can i change its path to another folder , because when i use setdatabasename function i cant set its path and it only searches application dir path
i want to be :
app dir path/Data/1.db -
You can not put a database file into the Qt resources (qrc). The reason is simply that Qt uses the unmodified sqlite library and passes the path to the database file to sqlite. And as sqlite is not aware of Qt at all and its resource system, it cannot find the file.
Additionally, even if it would work, the database in the resources would be read only!
What you can do is: Store the database in the resources and before using it the first time copy it to the real world file system. QFile is aware of the resources and can copy between those and the file system. Just make sure that you do not overwrite a modified database of the file system copy with the resource version.
-
In case of SQLite - and only there - setDatabaseName() takes the full path to the database file. It may be a single file name, in that case it is located in "the current directory", or some relative or absolute path + file name.
PS: I've added a "doc note":/doc/qt-4.8/qsqldatabase.html#notes