PDA

View Full Version : QSettings



Atomic_Sheep
13th October 2017, 10:35
Hi,

If you use a default constructor for QSettings, it automatically gets the values of:


QCoreApplication::setOrganizationName("MySoft");
QCoreApplication::setOrganizationDomain("mysoft.com");
QCoreApplication::setApplicationName("Star Runner");

That's all fine, but how do you then go about changing for example:


QSettings::format()

This only returns the format used, but if I don't specify it in the default constructor because I want the program to automatically get the values of my organisation and application names, then there's no way of specifying the format after?

Santosh Reddy
13th October 2017, 12:05
Use setDefaultFormat() before calling this constructor to change the default format used by this constructor.


That's it. There no way to change once the QSettings object is created.

Atomic_Sheep
16th October 2017, 09:15
Dang, thanks anyway.

A feature for future Qt versions? Wink wink... nudge nudge :).

d_stranz
22nd October 2017, 20:14
Create a wrapper class for QSettings (ie. one that uses a QSettings instance created on the fly) and use this wrapper class instead of QSettings itself. I think I posted such code here a month or so ago. You can customize that code to change the format on the fly if you wish by providing the format as an argument to the setValue() and value() methods. Each time the setValue() or value() method is called, the QSettings variable is created using the format and other constructor arguments (which could be member variables of the wrapper class or retrieved from qApp()), and that temporary QSettings instance is used to read or write the desired setting.