Adding db to resources
-
wrote on 7 Mar 2012, 10:58 last edited by
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 -
wrote on 7 Mar 2012, 11:23 last edited by
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.
-
wrote on 7 Mar 2012, 11:26 last edited by
can i move it to another directory?
-
wrote on 7 Mar 2012, 11:34 last edited by
Sure, you can put it anywhere you have write rights on the file system.
-
wrote on 7 Mar 2012, 11:35 last edited by
but in which function can i set its address?because setdatabasename function only sets a db name
-
wrote on 7 Mar 2012, 11:40 last edited by
How do you figure that? Set database name takes a complete path for the SQLite driver.
-
wrote on 7 Mar 2012, 11:43 last edited by
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
-
wrote on 7 Mar 2012, 12:15 last edited by
Actually, the same goes for the Borland Interbase (QIBASE) driver: it also takes a full file path. And I wrote an MSACCESS driver that did the same, but that one is not in Qt, so it does not count ;-)
-
wrote on 7 Mar 2012, 13:54 last edited by
Good to know, I've updated the note.
2/9