PDA

View Full Version : Data base sqlite



igoreshka3333
22nd August 2015, 16:24
Hi, how can I may to locate a data base in my project? I did the following. I adding a database witch situated on another disk in some folder:

m_mydb = QSqlDatabase::addDatabase( "QSQLITE" );
m_mydb.setDatabaseName( ":D/DB/EmployeeInfo.sqlite" );
But I want to locate it in the project folder. I have tried to add my data base to the project as a resource, first i have add a prefics /, in the project folder add a folder 'DB', in the qt appear a prefix '/' and a resource file DB/EmployeeInfo.sqlite
I have telling a path:

m_mydb.setDatabaseName( ":/DB/EmployeeInfo.sqlite" );
but it doesn't work, can you promt me?
Thanks.

ars
22nd August 2015, 17:03
Hello,

how should a database added as resource work? The resources are compiled into your program executable. Now assume you want to store some data into your database. This would imply that your program binary gets modified. This will not work.

Storing the database in the program installation folder is possible and, if permissions are set right, it may work. However, operating systems have set up some rules where application specific data should be stored. I recommend following those rules.

Best regards
ars

anda_skoa
22nd August 2015, 17:57
If the database is only ever read-only, you could include it as a resource and then extract it to a temporary file before working on it.
See QTemporaryFile::createNativeFile().

If you need it read/write, you could extract it to a writable location, e.g. using QStandardPaths::writableLocation()

Cheers,
_