Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 4

Qt-interest Archive, October 2007
QSettings - how to set INI format as default?


Message 1 in thread

Hi,

when constructing a QSettings instance with the default c'tor the 
entries made with

   QCoreApplication::setOrganizationName();
   QCoreApplication::setOrganizationDomain();
   QCoreApplication::setApplicationName();

are taken into account, as I understand.

But I don't see a way to specify the default format which I would like 
to be the INI format (also on Windows). I would like to call the default 
c'tor, but the documentation sais:

"The scope is QSettings::UserScope and the format is 
QSettings::NativeFormat."

The scope (UserScope) is perfect, but not the default format (NativeFormat).


As I really need to access the QSettings instance from various places 
(plugins, for example) that would mean that I need to make sure that one 
of the

   QSettings::QSettings(Format format, Scope scope,
                        const QString &organization,
                        const QString &application = QString(),
                        QObject *parent = 0);
   QSettings::QSettings(const QString &fileName, Format format,
                        QObject *parent = 0);

c'tors are called, with the proper arguments, which seem to be the only 
way to specify the desired Format.

But this would make e.g. calling setOrganizationDomain() (using the 1st 
c'tor from above) superfluous again, because 'organization' is already 
an argument. And as I understand the 2nd c'tor is more for /reading/ a 
specific (INI or registry) given entry.

Another approach would off course be to instantiate QSettings only once 
  and make this instance available with a singleton class or something 
(and tell everyone - okay, so far just me ;) - to use this singleton 
class instead of constructing your own QSettings).


Is this really the way to go (in Qt 4.3.2 btw), or did I miss something?

Thanks, Oliver

--
 [ signature omitted ] 

Message 2 in thread

Hi Till,

have a look at
http://trolltech.com/developer/task-tracker/index_html?method=entry&id=182712


\Ralf

--
 [ signature omitted ] 

Message 3 in thread

Till Oliver Knoll wrote:
> Another approach would off course be to instantiate QSettings only once 
>  and make this instance available with a singleton class or something 
> (and tell everyone - okay, so far just me ;) - to use this singleton 
> class instead of constructing your own QSettings).

Or possibly just subclass QSettings and have the subclass supply the 
base class with the format you want.  Then call your Settings c'tor 
anywhere you'd call the QSettings c'tor instead.

Darrik Mazey

--
 [ signature omitted ] 

Message 4 in thread

Darrik Mazey schrieb:
> Till Oliver Knoll wrote:
>> Another approach would off course be to instantiate QSettings only 
>> once  and make this instance available with a singleton class or 
>> something (and tell everyone - okay, so far just me ;) - to use this 
>> singleton class instead of constructing your own QSettings).
> 
> Or possibly just subclass QSettings and have the subclass supply the 
> base class with the format you want.  Then call your Settings c'tor 
> anywhere you'd call the QSettings c'tor instead.

Yes, that would also be an elegant solution. But still it would not 
solve the problem of telling everyone: "Hey don't use QSettings 
directly! Use either a) the singleton which provides an instance of 
QSettings or b) (your solution)"

But in the meantime I have realised that I am not alone ;)
(See 
http://trolltech.com/developer/task-tracker/index_html?method=entry&id=182712)

Cheers, Oliver

--
 [ signature omitted ] 

Message 5 in thread

Hi,

> But in the meantime I have realised that I am not alone ;)
> (See 
> http://trolltech.com/developer/task-tracker/index_html?method=entry&id=182712) 

It is a good idea. Once I've sent the PDF for the new edition of the Qt 
book to the publisher, I'll look at this task.

Cheers,

Jasmin

--
 [ signature omitted ]