I'm trying to make a global settings provider for an application. It seemed bulky to have one object duplicated in so many different classes.
I've seeth this method work when the private static variable was something simple, like an integer, but I want it to work for QSettings—an object.
// settings.h
class Settings {
public:
static void Initialize();
static int serverRefreshRate();
private:
QSettings *settings;
};
// settings.cpp
#include "Server/settings.h"
void Settings::Initialize() {
Settings::settings = new QSettings(/* etc */);
}
int Settings::serverRefreshRate() {
return settings->value("server/refreshRate", 10000).toInt();
}
Is there a way I can achieve this, or am I going about it in the wrong way?
Thanks!
EDIT,
Firstly, it needed to be:
static QSettings *settings;
And I needed the following in the .cpp.
QSettings* Settings::settings = NULL;