PDA

View Full Version : Synchronizing input and storage for settings



fruchtquark
28th November 2012, 14:51
Setting up a UI for settings and saving/loading settings via QSettings (http://qt-project.org/doc/qt-4.8/qsettings.html) are simple, but what is good practice for keeping these synchronized, e.g. populating the input fields with settings loaded, or saving when inputs change?
Input handling has to be done for verification anyway, so this may take care of saving data.
But for the other way around - is there some kind of standard list that could be iterated over to retrieve settings and write them to the respective user input? But this would need to be abstracted further and also keep track of the data type to choose the correct setters...

Further abstraction may use a settings tree (e.g. registry or Qt Creator Property Editor) which does away with a manual layout for input Widgets (I found older information on/implementation of this http://qtnode.net/wiki/Creating_Models_from_Scratch and http://doc.qt.digia.com/solutions/4/qtpropertybrowser/index.html). This approach is probably the most flexible, although maybe not acceptable for some end users. Possibly, a custom view could set up the UI in a similar fashion to the manual layout with labels and group boxes etc.

How do you do it?

PS:
All old links to this add-on refer to the Nokia site and are redirected to qt-project.org/ where this is not caught. I seem to have found the repositories for the add-ons: http://qt.gitorious.org/qt-solutions/qt-solutions/trees/master/qtpropertybrowser

This even features the "custom" view I was thinking about above.

License in header of http://qt.gitorious.org/qt-solutions/qt-solutions/blobs/master/qtpropertybrowser/src/qtpropertybrowser.cpp :


/************************************************** **************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of a Qt Solutions component.
**
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
** the names of its contributors may be used to endorse or promote
** products derived from this software without specific prior written
** permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
************************************************** **************************/

wysota
29th November 2012, 22:20
What is the actual question? QSettings should be all you need in this particular case unless I don't understand what you mean.