I have a database :/test.sqlite3 inside .qrc . And the goal is to directly use this database in the program. The database is read-only.
QSqlDatabase::setDatabase(":/test.sqlite3") does not work because Qt SQLite is not designed to work with the Qt file system.
One solution is to copy the database from .qrc to D:\temdb.sqlite3 and use it with QSqlDatabase::setDatabase("D:\\temdb.sqlite3") . But the program should not work with the OS file system.
The second solution stores :/dump.sql in resources, and then creates the database in memory using QSqlDatabase::setDatabase(":memory:") and imports a dump into it, reading and executing the lines from :/dump.sql . But this method is slow.
And finally, a tough but true way is to create your own Qt plugin for SQLite with a VFS implementation for reading the database from RAM, where we have bytes ":/test.sqlite3" .
Is there another easy way?
PS I already read all the questions, such as Converting a sqlite database into memory into a blob / char array and others, so do not mark it as a duplicate. My question is about any other methods.
sqlite qt qt5 vfs
Rinat
source share