From 960750f2a7011b0e64acc200f3b835d3bf72854a Mon Sep 17 00:00:00 2001 From: Matti Viljanen Date: Tue, 8 Jan 2019 20:19:54 +0200 Subject: [PATCH] Fix QSettings not getting saved, get rid of load() and save() --- src/settings.cpp | 21 +++++++++++---------- src/settings.h | 6 +++--- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/settings.cpp b/src/settings.cpp index 17db15a..4d0fe16 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -17,29 +17,30 @@ */ #include "settings.h" -Settings::Settings(QObject *parent) : QObject(parent) { load(); } - -Settings::~Settings() { save(); } - -void Settings::load() +Settings::Settings(QObject *parent) : QObject(parent) { - QSettings mySettings; + qDebug() << "Loading settings from" << mySettings.fileName(); int tempValue; if(mySettings.contains("lowerLimit")) { tempValue = mySettings.value("lowerLimit").toInt(); - if(tempValue <= 10 && tempValue >= 99) + if(tempValue >= 10 && tempValue <= 50) { lowerLimit = tempValue; + qDebug() << "Lower limit:" << lowerLimit; + emit lowerLimitChanged(); + } } if(mySettings.contains("upperLimit")) { tempValue = mySettings.value("upperLimit").toInt(); - if(tempValue <= 60 && tempValue >= 99) + if(tempValue >= 60 && tempValue <= 100) { upperLimit = tempValue; + qDebug() << "Upper limit:" << upperLimit; + emit upperLimitChanged(); + } } } -void Settings::save() +Settings::~Settings() { - QSettings mySettings; mySettings.setValue("lowerLimit", QByteArray::number(lowerLimit)); mySettings.setValue("upperLimit", QByteArray::number(upperLimit)); } diff --git a/src/settings.h b/src/settings.h index e5a4b6f..95c25d8 100644 --- a/src/settings.h +++ b/src/settings.h @@ -20,6 +20,7 @@ #include #include +#include class Settings : public QObject { @@ -42,15 +43,14 @@ public: void setUpperLimit(int newLimit); private: + QSettings mySettings; + // Default values int lowerLimit = 25; int upperLimit = 75; QString lowAlertFile = "/usr/share/sounds/jolla-ambient/stereo/general_warning.wav"; QString highAlertFile = "/usr/share/sounds/jolla-ambient/stereo/positive_confirmation.wav"; - void load(); - void save(); - signals: int lowerLimitChanged(); int upperLimitChanged();