Reputation:
Currently, I am using an SQLite database this way:
QSqlDatabase Database; Database.addDatabase("QSQLITE");
Database.setDatabaseName("C:/Users/ARASH/Desktop/arash.db");
But, this isn't permanent. Because the application will not work for a different desktop folder under a different user.
I want my application to run on other machines as well. So, I need a permanent solution for generalizing database path for every computer. Like: we can add pictures to resource.qrc
. I want to use database in that way.
Upvotes: 0
Views: 368
Reputation: 14617
You can use a DB path relative to your executable.
For example, you have a directory structure like this:
app folder
- executable
- data.db
So, it would be:
Database.setDatabaseName("data.db");
Alternatively, you can use QStandardPaths class to get the DesktopLocation
or other locations as per your requirements.
Upvotes: 3