Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
SQLite database file within qrc
Robey Mardon last edited by
Is it possible to insert a SQLite
.dbfile in a resource
Leonardo last edited by
I have never tried, but if it's a read only database, there's no reason for it not to be possible. Just try:
Robey Mardon last edited by Robey Mardon
@Leonardo Unfortunately it doesn't seems to work. I tried the way you said and nothing appears, then I tried using the full path for the database file and worked.
I just realized that it's not possible:
SQLite databases cannot be stored in the Qt resource system. You must put it into regular files and distribute them along your application.
The reason is simple: The database name is just the path to the file. Qt does not intercept the file name but hands it over directly to the SQLite functions (by calling toUtf8() on the “path”), which in turn try to open that file – and will eventually fail, of course.
Also, keep in mind that a file in a resource is read-only, you would never be able to write to that database.
Technically it can be embedded, BUT you can't make the QtSql module read it even less write it. What you can do however is put a copy of that "embedded" database in a suitable folder and then use it from your application. To get a suitable folder, use QStandardPaths.
Hope it helps