QSettings working on a QByteArray



  • Hi all,

    is there a way to use a QSettings from a file stored in a QByteArray?

    My idea is to put a lot of setting file in a DB and retrieve it with a query when needed. The query return me a QString or a QByteArray containing the setting file.

    Actually I must pass the QString to a QFile save it on a temporary file and pass the filename to a QSettings to use it:

    @
    QSettings setting("/tmp_dir/tmp_file.conf");
    @

    It should be useful to pass the QByteArray to the QSettings constructor.



  • You can use hard and long way - create custom implementation for QAbstractFileEngine and QAbstractFileEngineHandler. "Here":http://www.qtcentre.org/attachment.php?attachmentid=3501&d=1248628685 example from Wysota.

    Then you can just use own "prefix" like:

    @QSettings setting("MyFileEngineSystem:/file.conf");@



  • [quote author="SABROG" date="1284108063"]You can use hard and long way - create custom implementation for QAbstractFileEngine and QAbstractFileEngineHandler. "Here":http://www.qtcentre.org/attachment.php?attachmentid=3501&d=1248628685 example from Wysota.

    Then you can just use own "prefix" like:

    @QSettings setting("MyFileEngineSystem:/file.conf");@[/quote]

    Thanks,

    Isn't there any easy and short way? :-)



  • try this:

    @ bool readXmlFile(QIODevice &device, QSettings::SettingsMap &map);
    bool writeXmlFile(QIODevice &device, const QSettings::SettingsMap &map);

    int main(int argc, char *argv[])
    {
    const QSettings::Format XmlFormat =
    QSettings::registerFormat("xml", readXmlFile, writeXmlFile);

     QSettings settings(XmlFormat, QSettings::UserScope, "MySoft",
                        "Star Runner");
    
     ...
    

    }@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.