Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
adding sqlite file into qrc file system
divaindie last edited by
is it possible to add database file into qrc file system? I assume that we can add only binary files into qrc file,so even if we add a database file we cannot access it using "qrc://database_file " address (i guess qsqldatabase.setDatabaseName("qrc://database_file") will fail).am i right on this? .please suggest me a way through which i can add a database file into qrc file system to access it during my application execution.
It cannot use a db in a qrc directly.
You need to copy the db file to writable location when app starts.
and then open it from the new location.
Pablo J. Rogina last edited by
@divaindie in addition to @mrjj response, please keep in mind that deploying a DB from Qt resource system (qrc:) should be used for read-only DBs.
If you pack the DB into qrc:, then you copy from qrc: into OS and start using it, and the user updates DB content two things may happen:
- you won't be able to get that DB status into qrc: back again (doing so it will imply changing the executable of your Qt app...)
- Be careful in next app startup, since extracting the DB again will overwrite existing file which was previously updated...
divaindie last edited by divaindie
That question has already been asked many times. Please search the forum a bit.
QStandardPaths::writableLocation to the rescue.