[Interest] QWidget + friends; How to restore properties across sessions?
markg85 at gmail.com
Fri Aug 15 21:48:08 CEST 2014
This time i won't answer myself  since i've been thinking about a
possible solution for this for quite a while and never really figured
out something that would be sane.
Oke, here is the case:
- User opens an application filled with widgets. Each widget allows
the user to modify some part of a view.
- By default each widget is initialized with the default values as set
in QtDesigner (or in code). Values the user just changed.
- User closes application.
- User now opens the application again and all settings are back at
the defaults that where set in the .ui file or in code.
- User does some swearing and fills in the custom settings again.
I'm sure most of you folks out there that have ever made an
application has came across this issue. The "easy" way is to use
QSettings and maintain the settings on a per widget (and even per
property) basis in there and restore those settings when the
application opens again.
That approach works, but adds quite a bit of extra bookkeeping in
every widget that has properties that the user can change. Since every
widget now needs to maintain a list of possible settings, update them
when the user changes it and restore them when the application opens
Now i'm searching for alternatives to this approach to prevent
handling the bookkeeping myself and still have the same result. For
instance, would it be possible to have some function (in QObject or
QWidget i guess) where you either:
- Define which properties should be saved/restored across sessions,
bookkeeping would be done internaly.
- or just some "QObject::persistentSettings(bool)" function that -
when true - saves any properties and restores them upon next request
in a persistent manner.
In Qt each widget (all classes really) already have Q_PROPERTY for
about all properties. Would it be possible to use QSettings along with
the Q_PROPERTY macro to make property changes persistent?
To be clear, the intention for me is to have a simple way to remember
properties without managing the remembering part myself. That is
something i'm doing now and like to get rid of.
More information about the Interest