# HG changeset patch # User Matti Hamalainen # Date 1503486687 -10800 # Node ID f6685c2eb75d0b1c100683682632c903d4977eb5 # Parent d77779789e7667768aac4675cfc3c4c8163c7755 Store SQLite database and log file in application data directory instead of the executable directory itself. diff -r d77779789e76 -r f6685c2eb75d src/main.cpp --- 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 #include #include +#include #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()) {