Verified Commit 815e6b40 authored by Tobias Fella's avatar Tobias Fella Committed by Jonah Brüchert

Create the data location if it does not exist

Add error handling to database path creation
parent eeb78342
......@@ -30,6 +30,7 @@
#include <QSqlQuery>
#include <QStandardPaths>
#include <QVariant>
#include <QDir>
#include <exception>
......@@ -39,7 +40,13 @@
DBManager::DBManager(QObject *parent)
: QObject(parent)
{
QString dbname = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + QStringLiteral("/angelfish.sqlite");
QString dbpath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
QString dbname = dbpath + QStringLiteral("/angelfish.sqlite");
if(!QDir().mkpath(dbpath)) {
qCritical() << "Database directory does not exist and cannot be created: " << dbpath;
throw std::runtime_error("Database directory does not exist and cannot be created: " + dbpath.toStdString());
}
QSqlDatabase database = QSqlDatabase::addDatabase(QLatin1String("QSQLITE"));
database.setDatabaseName(dbname);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment