[SOLVED] how to use same db (SqLite) on all platforms?
I'm using a SqLite database and with full path to it is working ok on windows - but not on linux and not on android.
const QString dbType("QSQLITE");
qCritical() <<dbType << " database module not available.";
QString dbfile_path = QApplication::applicationDirPath() + "/db/test.db";
QSqlDatabase mydb = QSqlDatabase::addDatabase(dbType);
and so on...
now if I will use as
QString dbfile_path = "c:/myproject/test/db/test.db";
it will work on windows but not on linux or android
how can I do it to work on windows and on android and linux?
also i see it does not copy the test.db who is in the db folder to the
c:/myproject/build-test-Desktop_Qt_5_2_1_MinGW_32bit-Debug/debug/db - where is the place that to be
if I will add this
@qDebug() << dbfile_path;@
this is the output
but it does not copy the file there so this path does not exist instead the file is located at
please help me with this..
I would suggest to use "QStandardPaths":https://qt-project.org/doc/qt-5/qstandardpaths.html class to get the path to you storage location.
If you want to have your database in a known path on all platform, you should use "QStandardPaths":http://qt-project.org/doc/qt-5/qstandardpaths.html with DataLocation.
Most OS (even windows) will not allow you to create new files in the application folder from the application itself without e.g. administrator rights. And generally speaking, you should do that at all since every user could look/modify/destroy data of another user.
Hope it helps
ok.. but how to move/copy this at that known location
Generally you don't move it, you create the database directly there. If you are bundling an empty database with your application, just use QFile to copy it to the destination folder.
yes but how can be this done because on android I have to have a folder on the sdcard or on phone memory and on desktop I have to have that folder db made in the program's folder
You could save and read settings for every machine/user with QSettings.
this is true that you generally is nt a such need but in my case I wish to avoid having a import module on my program. any way the thing with path is very annoying . any way then how to create a new folder and new databese in it?? then i'l work for the update the tables from that database