Mercurial > hg > syntilista
changeset 129:f6685c2eb75d
Store SQLite database and log file in application data directory instead of
the executable directory itself.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 23 Aug 2017 14:11:27 +0300 |
parents | d77779789e76 |
children | 10c6bd84eb32 |
files | src/main.cpp |
diffstat | 1 files changed, 14 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main.cpp Wed Aug 23 13:41:01 2017 +0300 +++ b/src/main.cpp Wed Aug 23 14:11:27 2017 +0300 @@ -12,14 +12,15 @@ #include <QPrintDialog> #include <QPrintPreviewDialog> #include <QProgressDialog> +#include <QStandardPaths> #include "main.h" #include "ui_mainwindow.h" #include "ui_editperson.h" #include "ui_aboutwindow.h" -// Global UI scale factor -double setScale; +double setScale; // Global UI scale factor +QString appDataPath; // Application data path/directory // @@ -77,9 +78,9 @@ // void slLog(QString msg) { - QString filename = qApp->applicationDirPath() + QDir::separator() + APP_LOG_FILE; + QString filename = appDataPath + QDir::separator() + APP_LOG_FILE; QFile fh(filename); - if (fh.open(QIODevice::WriteOnly | QIODevice::Append)) + if (fh.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) { QTextStream out(&fh); out << @@ -225,11 +226,18 @@ QApplication sapp(argc, argv); // + // Create logfile and data directory + // + appDataPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation); + QDir path(appDataPath); + if (!path.exists(appDataPath)) + path.mkpath(appDataPath); + + // // Initialize / open SQL database connection // QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); - db.setDatabaseName(qApp->applicationDirPath() + - QDir::separator() + APP_SQLITE_FILE); + db.setDatabaseName(appDataPath + QDir::separator() + APP_SQLITE_FILE); if (!db.open()) {