PDA

View Full Version : Making an options/settings class



weevil
14th June 2010, 06:21
This is possibly more of a general C++ question. I need to have application settings data available (including public slots, enum constants and member objects) to most of the classes in my program concurrently, but I'm not sure how to do that. I know I can use QSettings() to store and retrieve settings, but I'd like to try and make my own settings class. The first thing that came to mind was to create a pointer to it in every class, but initializing it gets messy fast with having to track the child/parent relationships between each class in the inheritance chain.

I'm still learning about static functions and multiple inheritance, but I think what I want is to have each class inherit from my Settings class, and then make all of the get/set functions static, as well as the settings data members. If I understand correctly this will allow me to access the classes data without every instantiating an object of it, and each class that inherits from it can treat Settings get/set functions like their own? If anyone could help straighten out my thinking or point me in the right direction, I'd appreciate it. Also, while searching it seems I can't make static slots/signals, so in this case would I be unable to use them in such a class?

EDIT: I tried creating a Settings class with static member objects and functions, and inheriting from it with those classes that needed access to either, and it seems to be doing what I want. Someone chime in if there's a better way to handle this!

Ginsengelf
14th June 2010, 08:12
Hi you probably want a singleton.

Ginsengelf