Skip to content

czechtech/libqsharedsettings

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QSharedSettings Library - libqsharedsettings

Enhance QSettings for dynamic settings changes.

Typically, a QSettings object is instantiated for only two brief moments during a program's execution:

  • At the launch of an application to read it's previous state, and then
  • At the close of the application to save it's current state.

QSharedSettings is designed to have a persistent settings object that alerts the application whenever it's settings have been adjusted. These adjustments can be made internally by itself, or, more radically, by an external source such as a system-wide settings application or another cooperative application.

It helps to have an understanding of QSettings to fully understand the purpose of this library.

Installation

Download, compile, and install:

wget https://github.com/czechtech/libqsharedsettings/archive/master.zip
gunzip master.zip
cd libqsharedsettings-master
qmake && make && su -c 'make install'
cd ..
rm master.zip

Usage

Include QSharedSettings header file:

#include <qsharedsetting.h>

Add a persistent QSharedSettings member to the main class definition.

QSharedSettings m_settings;

Declare and define an appropriate slot.

void onChangedSettings(QStringList keys)  { ... }

Connect the signal/slot in the constructor of your main class.

connect(&m_settings, SIGNAL(settingsChanged(QStringList)), this, SLOT(onChangedSettings(QStringList)));

Now, whenever a setting or settings are changed, the settingsChanged(...) signal is added to the event queue with the keys of the settings which have changed. The onChangedSettings(...) slot is called, and the application can respond appropriately.

Notes

Before changing any settings internally, it sometimes makes sense to disconnect the signal/slot. Example: While saving the current state upon exit.

QSharedSettings creates another mechanism of inter-process communication. But, keep in mind, access to QSettings is restricted based on the QSettings Fallback Mechanism

The settingsChanged(...) signal does not differentiate between changed/added/removed. QSettings::contains(QString key) is most helpful.

Test Program

Included with the library is a demonstration.

cd libqsharedsettings-master/test
qmake && make

To see the demonstration, launch the test program.

./test

When "test" is executed it adds some settings, changes a setting, and removes a couple settings. The screen output occurs within Qt's main event loop. To truely appreciate what QSharedSettings can do, launch (and leave executing) the test program from two different terminals. Ctrl-C interrupts the program to exit.

To Do

  • Get away from the internal manual polling!,
  • Reimplement signalling each setting change so users can decide, and
  • Consider a mechanism to control which settings are shared, which are not.

The code functions well, but it could use some enhancements and bullet-proofing.

Uses

If you use this in a project, drop a line to have your project linked here.

About

Enhanced QSettings for dynamic settings changes

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published