[PyQt] QSettings usage - multiple?
Hans-Peter Jansen
hpj at urpla.net
Thu Oct 21 19:13:36 BST 2010
On Thursday 21 October 2010, 16:16:21 Baz Walter wrote:
> On 20/10/10 14:22, Randy Heiland wrote:
> > Hello,
> >
> > Is it possible to have multiple QSettings files for an app?
> > Basically, our situation is that we have an app and we save various
> > params associated with the app via the QSettings mechanism.
> > However, we'd like to be able to save/read different sets of
> > params. Perhaps we're mis-using the QSettings and should simply
> > save our app-specific params in a separate file? I'd welcome
> > suggestions and example scripts.
>
> why not save multiple groups of params using the same settings
> object?
>
> so do something like:
>
> settings.setValue("params-01/window/pos", self.pos())
> settings.setValue("params-01/window/size", self.size())
> ...
>
> settings.setValue("params-02/window/pos", self.pos())
> settings.setValue("params-02/window/size", self.size())
> ...
>
> which would result in an ini file like:
>
> [params-01]
> window\pos=@Point(794 473)
> window\size=@Size(400 400)
> ...
>
> [params-02]
> window\pos=@Point(794 473)
> window\size=@Size(400 400)
> ...
>
Randy, you didn't express yourself very well, but probably Baz has hit
the button. Usually, if people are after multiple config files, they
try to establish a hierarchical configuration management.
Anyway, did you noticed the
QSettings(const QString &fileName, Format format, QObject * parent = 0)
contructor. Because the config storage area differs significantly from
OS to OS, it is not very popular. You have to carry the OS dependancy
burden.
Hth,
Pete
More information about the PyQt
mailing list