Always feel that it is convenient to save configuration information with qsettings, in order to make the program more convenient to interact with Web programs and databases such as Mongodb,redis,postgresql, to add JSON format support for Qsettings
Source code Example:
Https://github.com/tsuibin/Json_format_for_QSettings/blob/master/main.cpp
#include <QApplication> #include <QJsonDocument> #include <QDebug> #include <QVariant> #include <qsettings>bool readjsonfile (qiodevice &device, QSETTINGS::SETTINGSMAP&NBSP;&MAP) {bool ret = false; Qjsonparseerror error;map = qjsondocument::fromjson (Device.readall () , &error). Tovariant (). Tomap (); if ( error.error == QJsonParseError::NoError ) ret = true; Return ret;} Bool writejsonfile (Qiodevice &device, const qsettings::settingsmap &map) { bool ret = false; Qjsondocument jsondocument = qjsondocument::fromvariant (Qvariant::fromvalue (map));if ( device.write (Jsondocument.tojson ()) != -1 ) Ret = true;return ret;} Int main (int argc, char *argv[]) {qcoreapplication a (ARGC,&NBSP;ARGV);const Qsettings:: Format jsonformat = qsettings::registerformat ("JSON", readjsonfile, writejsonfile); Qsettings settings (jsonformat, qsettings::userscope, "JSON", "Cazool"); Qmap<qstring, qvariant> cazooldata;cazooldata.insert ("Address", "China"); Cazooldata.insert ("The Age Cazooldata.insert ("Tel", "13888888888"), Settings.remove ("Tsuibin"); Settings.setvalue ("Cazool", Qvariant::fromvalue (Cazooldata)); Return a.exec ();}
JSON format support for Qsettings