[Interest] Write QSettings to a QString in INI format

Murphy, Sean smurphy at walbro.com
Sat Oct 26 17:31:02 CEST 2019


> > Because QSettings has the file locked. Make sure settings goes out of
> > scope before you re-open the file.
> >
> Granted, it's complex with the locking code, but underneath it all you have
> this hidden gem writeIniFile(), which takes a QIODevice and the map (you
> know, the function with those hardwired [General] and [General%] strings).
> 
> Suggestion: you have this nice extension/plugin call
> QSettings::registerFormat(), which takes a readFunc and a writeFunc ptr.
> If that writeIniFile() could be exposed as a public writeFunc ptr (yes it has the
> same function signature) then you could have users bypass the locking stuff,
> by requiring them to register a new format (say with the extension "buffer"
> for a QBuffer) but allowing them to reuse the existing writeIniFile() as their
> own writeFunc (and say a QBuffer as the QIODevice).
> That way you could access the streaming functionality of QSettings without
> involving the file system.

Is the suggestion to me, or to the Qt development team? Because even if I 
somehow expose the writeIniFile() function so that I can use it, the only 
applicable QSettings constructor that allows me to specify a registered format
is this one:
    QSettings(const QString &fileName, QSettings::Format format, QObject *parent = nullptr)
And the behavior of that constructor is that it opens an actual file on the 
filesystem with "fileName" (use an existing file if the file already existed before 
this call, otherwise creating a file with that name if it didn't already exist), then 
sets the QIODevice to point at the file, and then uses your registered format's 
function pointers to handle the reading and writing of it. There does not appear 
to be any way for me to point the created QSettings object at my QBuffer, even 
if I got access to the writeIniFile(), correct? Or am I missing something?

Sean


This message has been scanned for malware by Forcepoint. www.forcepoint.com


More information about the Interest mailing list