[Interest] Best practices for settings
Tomasz Siekierda
sierdzio at gmail.com
Sun Nov 17 17:29:36 CET 2013
On 17 November 2013 14:53, Tim Hoffmann <thoffmann at texstudio.org> wrote:
> Hi all,
Hi
> Are there any best practices for working with QSettings in larger
> projects with many settings?
I'm not claiming the ones I will list are "the best", but they do work
quite well in several projects I'm involved in.
> In particular:
> - How do you efficiently synchronize settings with widgets in an options
> dialog.
The settings class is a Singleton, and all options are accesible
through member variables (private + getters and setters, or public -
if you prefer). Although I personally believe Singletons are evil,
they can be useful - and this is one of the place where the benefits
outweight the problems.
> - How do you efficiently detect changes made in an option dialog. (I
> have some options that need significant calculations after changing.
> These should only be triggered if the corresponding setting was actually
> changed.)
The settings class stores everything through members, with
corresponding getters and setters. So in your dialog, you just need to
check if the value is the same as the one returned by the getter.
> - How do you access the settings in the source code? Always casting the
> QVariants seems a bit tedious but the alternative would be to have
> additional local variables (or members) for the values which you would
> have to maintain additionally.
As said: getters and setters :)
Cheers,
sierdzio
More information about the Interest
mailing list