[SOLVED]What would be the best way to have database support in my application.
-
wrote on 21 Feb 2016, 21:12 last edited by
Hi SGaist, thanks for the comment, as per usual it's right to the point.
I will implement it this way. -
wrote on 21 Feb 2016, 21:23 last edited by
You don't need to create your database programmatically. You could create an empty database with all your tables and relationships and store it as a resource in your app. Then you would copy this resource to a writable location if it didn't exist yet. That's what I suggested. It would be like a template database.
-
wrote on 21 Feb 2016, 21:33 last edited by
Indeed, it should be faster too.
-
wrote on 23 Feb 2016, 21:20 last edited by
The location created from this command
db_path = QDir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)).filePath("database.db");
does not seem to actually exist in my system, moreover the
copy
command fails.Is it normal that
db_path
returns a location that does not exist? -
What value are you getting ?
-
wrote on 23 Feb 2016, 21:31 last edited by
db_path has a value of
"C:/Users/eali/AppData/Roaming/ealione/v002/database.db"
-
Looks good
What is your problem with it ?
-
wrote on 23 Feb 2016, 21:37 last edited by
Maybe you think the folder doesn't exist because the "AppData" folder is hidden by default.
-
wrote on 23 Feb 2016, 21:43 last edited by
Looks correct indeed, the thing is that it does not exist (not simply hidden), and the copy command:
QFile::copy(":assets/database/database.db", db_path
returns false. -
wrote on 23 Feb 2016, 21:48 last edited by rturrentine
Is ":assets" Android specific? Also should it be "assets:/datatbase...."
-
wrote on 23 Feb 2016, 21:48 last edited by Leonardo
QStandardPaths returns a writable path for you. It doesn't guarantee you that it exists. If if doesn't, create it using QDir.mkpath()
http://doc.qt.io/qt-5/qdir.html#mkpath
As you know it's a writable location, it won't be a problem.
=========
@rturrentine is right also. ":assets" is for android. For Qt resources, you should use ":/database/database.db".
-
wrote on 23 Feb 2016, 21:54 last edited by
BTW, here is a link to a related post:
14/16